【问题标题】:UITableView second prototype cell does not appear to be respecting custom height?UITableView 第二个原型单元格似乎不尊重自定义高度?
【发布时间】:2015-08-09 19:32:41
【问题描述】:

我正在使第二个原型单元出队,但单元的高度似乎没有得到尊重。

谁能引导我朝着正确的方向前进?我已经尝试搜索谷歌无济于事。


问题已经解决了,我的解决方案是用代码实现的:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat height;
    if ([indexPath row] == 0) {
        height = 170.0f;
    }
    else  {
        height = 72.0f;
    }
    return height;
}

【问题讨论】:

    标签: ios uitableview cocoa-touch storyboard uikit


    【解决方案1】:

    您需要实现表格视图委托方法heightForRowAtIndexPath: 才能更改单元格的高度。您不能仅在情节提要中做到这一点。

    【讨论】:

    • 非常感谢!我不知道故事板不尊重这方面
    • 没问题 :) 只是不要忘记勾选绿色复选标记 :)
    【解决方案2】:

    记住

    storyboards 或 xib 无法在没有代码的情况下将单元格出列,因此您必须设置委托并写入代码tableView:heightForRowAtIndexPath

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        CGFloat height;
        if ([indexPath row] == 0) {
            height = 100.f;
        }
        else  {
            height = 50.f;
        }
        return height;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-06-12
      • 2011-11-27
      • 1970-01-01
      • 2021-09-17
      • 1970-01-01
      • 2019-06-14
      • 1970-01-01
      • 2013-07-17
      • 2012-08-12
      相关资源
      最近更新 更多