我试图返回heightForRowAtIndexPath
委托方法中detailTextLabel
的高度。这样我的表格视图单元应该和我的detailTextLabel
一样高。设置UITableViewCell的正确高度
- (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;
}
但是我在下面的行得到一个EXC_BAD_ACCESS
:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
WATS错上面这段代码?
'-tableView:heightForRowAtIndexPath:'在'-tableView:cellForRowAtIndexPath:'过程中被调用,所以当你调用'-cellForRowAtIndexPath:'时,单元还没有被完全创建,所以你不能引用它。 –
[如何访问tableView中的cell.textLabel.text:heightForRowAtIndexPath:from tableView:cellForRowAtIndexPath:](http://stackoverflow.com/questions/3903136/how-to-access-cell-textlabel-text-in -tableviewheightforrowatindexpath-from-tab)以及许多其他许多 – jrturton