【发布时间】:2013-04-10 13:46:43
【问题描述】:
我有一张带有静态单元格的表格。对于一个单元格,我想根据标签的高度(在该单元格内)更改其高度,同时保持所有其他单元格的高度不变。如何获取当前单元格的高度?或者也许有更好的方法?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath section] == 2) {
return self.myLabel.frame.origin.y *2 + self.myLabel.frame.size.height;
} else {
return ...; // what should go here, so the cell doesn't change its height?
}
}
【问题讨论】:
-
你的单元格的默认高度在那里。 44 如果你没有改变任何东西。
-
您也可以使用 UIKIt 对 NSString 方法的扩展
sizeWithFont:计算单元格实际需要的标签高度。
标签: ios objective-c uitableview