heightForRowAtIndexPath并自定义tableviewcell height

时间:2015-06-22 23:26:27

标签: ios uitableview height customization

我想知道我是否定制了自己的具有指定高度的tableviewcell,这个值与我在heightForRowAtIndexPath中使用的值不同。哪个高度将用于细胞。由于我在一个tableview中有多个自定义单元格,因此我很难在heightForRowAtIndexPath函数中区分它们的每种类型。我只是想知道在这种情况下,我可以使用我为每种类型的细胞定义的细胞高度吗?

3 个答案:

答案 0 :(得分:2)

您可以实现UITableViewDelegate

的此方法
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    //The height you desire to have for the row at *indexPath*

    }

答案 1 :(得分:0)

根据UITableViewDelegate protocol reference

  

该方法允许委托指定具有不同高度的行。如果实现了此方法,则它返回的值将覆盖为给定行的UITableView的rowHeight属性指定的值。

答案 2 :(得分:0)

我发现在iOS8之前,你必须在heightForRowAtIndexPath中指定行高。在iOS8之前,Apple提供自动布局和大小调整,例如,添加约束。 不确定这是否是控制细胞行高度的唯一方法。