uitableview - Calculate custom UITableViewCell height at "indexPath" from -tableView:cellForRowAtIndexPath:? -
i adjust height of custom uitableviewcell
inside custom class, , believe need use -tableview:cellforrowatindexpath:
method adjust height of cell. attempting adjust height of custom cell in custom cell class, grab cell @ given index path cast it, , return height of cell this:
- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath; { customuitableviewcell *cell = (customuitableviewcell *)[tableview cellforrowatindexpath:indexpath]; return cell.frame.size.height; }
but getting stack overflow. better way around doing this?
the table view delegate
first call heightforrowatindexpath:
, datasource
construct cell in cellforrowatindexpath:
after based on computed information.
therefore approach not work.
you need have logic computing height. (e.g. if displaying text height might dynamic , depend on amount of text - calculate nsstring
method.)
if displaying few types of cells fixed heights, define these heights constants , return correct height based on same logic have in cellforrowatindexpath:
decide cell use.
#define kbasiccellheight 50 #define kadvancedcellheight 100 - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { if (needtousebasiccellatthisindexpath) { return kbasiccellheight; } return kadvancedcellheight; }
Comments
Post a Comment