How does one obtain the UITableViewCell
when within the heightForRowAtIndexPath
method, i.e. given the indexPath?
(then I could access the
The obvious answer is to call cellForRowAtIndexPath
, but you may have already discovered there are some issues with that. See this question if you haven't already: UITableView flexible/dynamic heightForRowAtIndexPath
For my last project I used a custom subclass of UICell and implemented a method like this. I then called this from table:heightForRowAtIndexPath:
(after looking up the content for that row).
+ (CGFloat) heightOfContent: (NSString *)content
{
CGFloat contentHeight =
[content sizeWithFont: DefaultContentLabelFont
constrainedToSize: CGSizeMake( DefaultCellSize.width, DefaultContentLabelHeight * DefaultContentLabelNumberOfLines )
lineBreakMode: UILineBreakModeWordWrap].height;
return contentHeight + DefaultCellPaddingHeight;
}