【问题标题】:heightForRowAtIndexPath and customize tableviewcell heightheightForRowAtIndexPath 并自定义 tableviewcell 高度
【发布时间】:2015-09-08 14:07:11
【问题描述】:

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

【问题讨论】:

    标签: ios uitableview height customization


    【解决方案1】:

    根据UITableViewDelegate protocol reference

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

    【讨论】:

      【解决方案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 提供了单元格的自动布局和调整大小,例如添加约束。 不确定这是否是控制单元格行高的唯一方法。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-07-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-02-19
          • 1970-01-01
          相关资源
          最近更新 更多