ios - How to use UITableView to display 2 UILabels and a grid of images, also auto update the Cell height -
i need build uitableview
display list of posts, , each post contain 3 sections.
- title (uilabel 1 line of text)
- content (uilabel multi lines of texts)
- grid of images (number of images vary each row)
i have followed this post.
i able add title , content, , autolayout works need to. however, cannot add grid of images.
i have create custom cell view class autosizecell.h/autosizecell.m
in above post. have created modal class have 3 properties (title, content , nsmutablearray
of image names need display in grid) however, seems cannot pass images names autosizecell.m
, cannot display image grid.
@implementation autosizecellcontents -(id)init { self = [super init]; if (self) { self.images = [[nsmutablearray alloc] init]; } return self; } @end
controller:
-(void)configurecell:(autosizecell *)cell atindexpath:(nsindexpath *)indexpath { // configure cell indexpath cell.category.text = [self getcategoryatindexpath:indexpath]; cell.pasttense.text = [self getpasttenseatindexpath:indexpath]; (nsstring *imagename in [self getimagesatindexpath:indexpath]) { nslog(@"image name %@",imagename); [cell.images addobject:@"hellp"]; } } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { // create reusable cell autosizecell *cell = [tableview dequeuereusablecellwithidentifier:@"plerp"]; if(!cell) { cell = [[autosizecell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:@"plerp"]; [self configurecell:cell atindexpath:indexpath]; } return cell; }
i believe need override -(id)initwithcoder:(nscoder*)adecoder
instead of init
.
alternatively, don't either of these things. rid of init entirely , this.
cell.images = [self getimagesatindexpath:indexpath]
less code, less relying on cell state. , i'm pretty sure adding images going cause issues when cell gets reused unless override prepareforreuse
. setting whole array easier.
Comments
Post a Comment