iphone - Change UICollectionViewCell content and nib layout based on data -
i have uicollectionview displaying many uicollectionviewcells have subclassed cardcell. pass variable "type" cardcell in - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath
want cardcell class able load different nib file depending on type passed in. different types need have different layouts.
the problem cannot figure out change in cardcell.m. tried using - (void)prepareforreuse
not call unless user scrolling.
you should register each nib file need in viewdidload, (substituting correct names nib file , identifier):
[self.collectionview registernib:[uinib nibwithnibname:@"rdcell" bundle:nil] forcellwithreuseidentifier:@"firsttype"];
then, in itemforrowatindexpath, test type , return correct type of cell:
- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { if (type = @"firsttype") { firstcell *cell = (firstcell *) [collectionview dequeuereusablecellwithreuseidentifier:@"firsttype" forindexpath:indexpath]; return cell; }else{ secondcell *cell = (secondcell *) [collectionview dequeuereusablecellwithreuseidentifier:@"secondtype" forindexpath:indexpath]; cell.whatever ..... return cell; } }
Comments
Post a Comment