ios - UICollection View Detail View -
my problem this. have collection view, works. not know how information passed details page. have tried 'prepareforsegue' method, created browser class have no clue how information passed view controller array created. please advise.
@interface maincollectionviewcontroller () @end @implementation maincollectionviewcontroller @synthesize menubtn; - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; uirefreshcontrol *refreshcontrol = [[uirefreshcontrol alloc] init]; [self.collectionview addsubview:refreshcontrol]; // additional setup after loading view. nsstring *filename = [nsstring stringwithformat:@"%@/main.rss", [mainutil getdocumentroot]]; _articlelistmain = [nsarray arraywithcontentsoffile:filename]; // additional setup after loading view. //menu self.view.layer.shadowopacity =0.75f; self.view.layer.shadowradius = 10.0f; self.view.layer.shadowcolor = [uicolor blackcolor].cgcolor; if (![self.slidingviewcontroller.underleftviewcontroller iskindofclass:[menuviewcontroller class]]) { self.slidingviewcontroller.underleftviewcontroller = [self.storyboard instantiateviewcontrollerwithidentifier:@"menu"]; } [self.view addgesturerecognizer:self.slidingviewcontroller.pangesture]; self.menubtn = [uibutton buttonwithtype:uibuttontypecustom]; menubtn.frame = cgrectmake(20, 0, 49, 54); [menubtn setbackgroundimage:[uiimage imagenamed:@"menubutton.png"] forstate:uicontrolstatenormal]; [menubtn addtarget:self action:@selector(revealmenu:) forcontrolevents:uicontroleventtouchupinside]; [self.view addsubview:self.menubtn]; } #pragma mark - uicollectionviewdatasourcedelegate - (nsinteger) numberofsectionsincollectionview:(uicollectionview *)collectionview { return 1; } - (nsinteger) collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { return [_articlelistmain count]; } - (uicollectionviewcell *) collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { maincollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"articlecellmain" forindexpath:indexpath]; nsdictionary *item = [_articlelistmain objectatindex:indexpath.item]; // retrieve url of user's avatar , assign uiimageview nsurl *userimgurl = [nsurl urlwithstring:[item objectforkey:@"image"]]; nsdata *userimgdata = [nsdata datawithcontentsofurl:userimgurl]; uiimage *userimage = [uiimage imagewithdata:userimgdata]; [cell.image setimage:userimage]; // set text of title uilabel cell.title.text = [nsstring stringwithformat:@"%@\n\n\n\n", [item objectforkey:@"title"]]; // set text of summary uilabel cell.description.text = [nsstring stringwithformat:@"%@\n\n\n\n\n\n\n\n\n", [item objectforkey:@"description"]]; cell.targeturl = [item objectforkey:@"link"]; return cell; } - (uicollectionreusableview *)collectionview:(uicollectionview *)collectionview viewforsupplementaryelementofkind:(nsstring *)kind atindexpath:(nsindexpath *)indexpath { uicollectionreusableview *reusableview = nil; if (kind == uicollectionelementkindsectionheader) { collectionheaderview *headerview = [collectionview dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier:@"headerview" forindexpath:indexpath]; uiimage *headerimage = [uiimage imagenamed:@"jol_logo.png"]; reusableview = headerview; } if (kind == uicollectionelementkindsectionfooter) { uicollectionreusableview *footerview = [collectionview dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionfooter withreuseidentifier:@"footerview" forindexpath:indexpath]; reusableview = footerview; } return reusableview; } - (ibaction)revealmenu:(id)sender { [self.slidingviewcontroller anchortopviewto:ecright]; } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { maincollectionviewcell *selectedcell = (maincollectionviewcell *)sender; mainbrowserviewcontroller *targetvc = (mainbrowserviewcontroller *) [segue destinationviewcontroller]; targetvc.targeturl = selectedcell.targeturl; } @end
you don't value cell. cells displaying data -- never query cell data, query data source use populate cell. can indexpath of sender:
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(maincollectionviewcell *)sender { mainbrowserviewcontroller *targetvc = (mainbrowserviewcontroller *) [segue destinationviewcontroller]; nsindexpath *indexpath = [self.collectionview indexpathforcell:sender]; nsdictionary *item = [_articlelistmain objectatindex:indexpath.item]; nsurl *targeturl = [item objectforkey:@"link"]; targetvc.targeturl = targeturl; }
Comments
Post a Comment