【发布时间】:2011-04-21 01:05:34
【问题描述】:
我想使用(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 自定义 UITableViewCell 高度。
我试图通过将textLabel 中的行数乘以每行的高度,然后为字幕添加10.0f 来获得UITableViewCell 的高度。我正在使用以下代码并获得exc_bad_access()。为什么?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return ([[[tableView cellForRowAtIndexPath:indexPath] textLabel] numberOfLines] * [[[[tableView cellForRowAtIndexPath:indexPath] textLabel] font] lineHeight]) + 10.0;
//return kRowHeightiPod; //A constant value for a sanity check
}
【问题讨论】:
-
看看这个问题。如果你看答案的第二部分,相信你会找到解决方案stackoverflow.com/questions/129502/…
-
@Aaron - 我相信它应该更简单。我不应该为我的单元重新定义一个矩形。我应该能够根据行数简单地计算高度。我正在尝试为我的行高和行值数获取浮点值。
-
我认为最终,该解决方案将被证明是最简单的,您还没有单元格矩形。
标签: iphone objective-c uitableview uilabel row-height