我有一個靜態單元格的表格。對於一個細胞,我想根據標籤的高度(在細胞內)改變其高度,同時保持所有其他細胞高度不變。我如何獲得當前細胞的高度?或者,也許有更好的方法?heightForRowAtIndexPath中的當前單元格高度?
- (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如果你沒有改變任何東西。 – Desdenova 2013-04-10 13:50:58
您還可以使用UIKIt對NSString方法'sizeWithFont:'的擴展來計算標籤的單元實際所需高度。 – 2013-04-10 13:56:23