Setting the correct height of a UITableViewCell
- by iOS explorer
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?