ios - Collection view is crashing for some reason -
//collection view uicollectionviewflowlayout *layout=[[uicollectionviewflowlayout alloc] init]; self.collectionview=[[uicollectionview alloc] initwithframe:self.view.frame collectionviewlayout:layout]; [self.collectionview setdatasource:self]; [self.collectionview setdelegate:self]; [self.collectionview registerclass:[uicollectionviewcell class] forcellwithreuseidentifier:@"cellidentifier"]; [self.collectionview setbackgroundcolor:[uicolor redcolor]]; [self.view addsubview:self.collectionview]; } - (nsinteger)collectionview:(uicollectionview *)tcollectionview numberofitemsinsection:(nsinteger)section { return 15; } // cell returned must retrieved call -dequeuereusablecellwithreuseidentifier:forindexpath: - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { uicollectionviewcell *cell=[collectionview dequeuereusablecellwithreuseidentifier:@"cellidentifier" forindexpath:indexpath]; cell.backgroundcolor=[uicolor greencolor]; return cell; } - (cgsize)collectionview:(uicollectionview *)collectionview layout:(uicollectionviewlayout*)collectionviewlayout sizeforitematindexpath:(nsindexpath *)indexpath { return cgsizemake(50, 50); }
crash on :
-[nsisunrestrictedvariable collectionview:numberofitemsinsection:]: unrecognized selector sent instance 0x7fce804111b0
what ? (the collection view inside view controller,tand inside scrollview)
it looks uicollectionview
has been deallocated memory still trying access it.
enable nszombies
, you'll see make call deallocated memory , fix code accordingly.
Comments
Post a Comment