ios - How to register custom CollectionViewCell? -


i have been far using uitableviews successfully, can't uicollectionview working.

@interface newscollectionviewdatasource : nsobject <uicollectionviewdatasource, uicollectionviewdelegate>  -(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath {     tncollectionviewcell *newscell = nil;     newscell = [collectionview dequeuereusablecellwithreuseidentifier:newscellreuseidentifier forindexpath:indexpath];     if (!newscell) {         [[nsbundle bundleforclass:[self class]] loadnibnamed:@"tncollectionviewcell" owner:self options:nil];     }     newscell.newslabel.text = [[self newsforindexpath:indexpath] headline];     return newscell; } 

everytime everytime line:

newscell.newslabel.text = [[self newsforindexpath:indexpath] headline]; 

newscell nil.

am registering wrong?

somewhere before retrieving cells collectionview (i.e. in viewdidload) call following method of uicollectionview

- (void)registernib:(uinib *)nib forcellwithreuseidentifier:(nsstring *)identifier; 

in case that:

[self.collectionview registernib:[uinib nibwithnibname:@"tncollectionviewcell" bundle:nil]        forcellwithreuseidentifier:newscellreuseidentifier]; 

and there no need following code:

if (!newscell) {     [[nsbundle bundleforclass:[self class]] loadnibnamed:@"tncollectionviewcell" owner:self options:nil]; } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -