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
Post a Comment