【问题标题】:heightForRowAtIndexPath and customize tableviewcell heightheightForRowAtIndexPath 并自定义 tableviewcell 高度
【发布时间】:2015-09-08 14:07:11
【问题描述】:
我想知道我是否自定义了我自己的具有指定高度的tableviewcell,并且这个值与我在heightForRowAtIndexPath中使用的值不同。哪个高度将用于单元格。由于我在一个 tableview 中有多个自定义单元格,因此我很难在 heightForRowAtIndexPath 函数中区分它们的每种类型。我只是想知道在这种情况下,我可以只使用我为每种类型的单元格定义的单元格高度吗?
【问题讨论】:
标签:
ios
uitableview
height
customization
【解决方案2】:
你可以实现UITableViewDelegate的这个方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//The height you desire to have for the row at *indexPath*
}
【解决方案3】:
我发现在iOS8之前,你必须在heightForRowAtIndexPath中指定行高。在 iOS8 之前,Apple 提供了单元格的自动布局和调整大小,例如添加约束。
不确定这是否是控制单元格行高的唯一方法。