Setting the correct height of a UITableViewCell
Posted
by
iOS explorer
on Stack Overflow
See other posts from Stack Overflow
or by iOS explorer
Published on 2011-11-18T17:48:29Z
Indexed on
2011/11/18
17:51 UTC
Read the original article
Hit count: 192
I'm trying to return the height of the detailTextLabel in the heightForRowAtIndexPath delegate method. This way my table view cells should be the same height as my detailTextLabel.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *text = cell.detailTextLabel.text;
CGSize size = cell.detailTextLabel.bounds.size;
UIFont *font = cell.detailTextLabel.font;
CGSize labelSize = [text sizeWithFont:font
constrainedToSize:size
lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height;
}
However I'm getting a EXC_BAD_ACCESS on the following line:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
Wats wrong with the above piece of code?
© Stack Overflow or respective owner