lundi 30 mars 2015

ios cell filling design pattern

I have a collection cell which used in multiple screens and setting lots of data in it. Which approach is better, setting data in UIViewController or in UICollectionviewCell? I didn't see second much but i don't know how to find right design pattern for this. As example:


First:



@implementation ProductViewController:UIviewController
{
-(UICollectionviewCell*)CellForIndexpath:(UIcollectionview*) collectionview..{
myCell *cell=[collectionview dequecellwithcellidentifier:@"cell"];
Product *pr=[datasource objectAtIndex:indexpath.row];
cell.lblName.text=pr.name;
cell.lblSize.text=pr.size;
[cell.imgCover setimage:pr.image];
..
return cell;
}
}


second:



@implementation ProductViewController:UIviewController
{
-(UICollectionviewCell*)CellForIndexpath:(UIcollectionview*) collectionview..{
myCell *cell=[collectionview dequecellwithcellidentifier:@"cell"];
Product *pr=[datasource objectAtIndex:indexpath.row];
[cell initProduct:pr];
return cell;
}
}
@implemeantation myCell:UICollectionviewCell{
-(void)initProduct:(Product*)pr{
self.lblName.text=pr.name;
self.lblSize.text=pr.size;
[self.imgCover setimage:pr.image];
..
}
}

Aucun commentaire:

Enregistrer un commentaire