ios - UICollectionViewCell Custom Segue ViewController Connection error -
at current have following code shown below:
groupsviewcontroller.m
#import "groupsviewcontroller.h" #import "groupshomeviewcontroller.h" #import "customcell.h" @interface groupsviewcontroller () { nsarray *arrayofimages; nsarray *arrayofdescriptions; nsstring * _titlefornextvc; } @end @implementation groupsviewcontroller { nsstring *reuseidentifier; } - (void)viewdidload { [super viewdidload]; [[self groupscollectionview]setdatasource:self]; [[self groupscollectionview]setdelegate:self]; reuseidentifier= @"smallicon"; arrayofimages = [[nsarray alloc]initwithobjects:@"a.png",@"b.png",@"c.png",nil]; arrayofdescriptions = [[nsarray alloc]initwithobjects:@"a",@"b",@"c",nil]; } -(nsinteger)numberofsectionsincollectionview:(uicollectionview *)collectionview { return 1; } -(nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { return [arrayofdescriptions count]; } -(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { customcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:reuseidentifier forindexpath:indexpath]; [[cell iconimage]setimage:[uiimage imagenamed:[arrayofimages objectatindex:indexpath.item]]]; [[cell iconlabel]settext:[arrayofdescriptions objectatindex:indexpath.item]]; return cell; } - (void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath { customcell *cell = (customcell *) [self collectionview:collectionview cellforitematindexpath:indexpath]; _titlefornextvc = cell.iconlabel.text; } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([segue.identifier isequaltostring:@"groupshomesegue"]) { groupshomeviewcontroller *vc = (groupshomeviewcontroller *)segue.destinationviewcontroller; vc.titletext = _titlefornextvc; } } - (void)settitletext:(nsstring *)titletext { _titletext = _titlefornextvc; // set title of viewcontroller self.title = _titletext; } - (void)didreceivememorywarning { [super didreceivememorywarning]; //dispose of resources can recreated. } // toggle view button - (ibaction)celltoggleaction:(id)sender { if([reuseidentifier isequaltostring:@"smallicon"]){ reuseidentifier=@"listview"; [sender setimage:[uiimage imagenamed:@"largeicon"]]; } else if ([reuseidentifier isequaltostring:@"listview"]){ reuseidentifier=@"largeicon"; [sender setimage:[uiimage imagenamed:@"smallicon"]]; } else if ([reuseidentifier isequaltostring:@"largeicon"]){ reuseidentifier=@"smallicon"; [sender setimage:[uiimage imagenamed:@"listview"]]; } [self.groupscollectionview reloaddata]; } //toggled cell sizes - (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout *)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath { cgsize cellsize; if([reuseidentifier isequaltostring:@"smallicon"]) cellsize = cgsizemake(100, 130); else if ([reuseidentifier isequaltostring:@"listview"]) cellsize = cgsizemake(320, 50); else if ([reuseidentifier isequaltostring:@"largeicon"]) cellsize = cgsizemake(320, 360); return cellsize; } @end groupshomeviewcontroller.m
#import "groupshomeviewcontroller.h" @interface groupshomeviewcontroller () @end @implementation groupshomeviewcontroller -(void)viewdidload{ [super viewdidload]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } @end well problem seems cannot new viewcontroller via custom segue once have clicked on 1 of uicollectionviewcells. click cell in uicollectionview , title disappears nothing else. should open groupshomeviewcontroller , set title of view controller label placed within cell have clicked. can't see if current title work either can't mygroupshomeviewcontroller display.
i assume missing line of code somewhere along lines, struggling find out or can due receiving no error message's @ all.
also point out new , have been developing app in spare time past month or so. appreciated if me problem , thank in advance direction may missing.
so problem need save off "what ever" trying pass next view controller in property. in case think have in _titlefornextvc
next need name segue in storyboard e.g "groupshomesegue" can
- (void)collectionview:(uicollectionview *)collectionview didselectitematindexpath:(nsindexpath *)indexpath { customcell *cell = (customcell *) [self collectionview:collectionview cellforitematindexpath:indexpath]; _titlefornextvc = cell.iconlabel.text; [self performseguewithidentifier:@"groupshomesegue" sender:self]; } then work
Comments
Post a Comment