【问题标题】:Can't change UITableViewCell contentView height无法更改 UITableViewCell contentView 高度
【发布时间】:2014-11-23 17:51:05
【问题描述】:

我有一个自定义的uitableviewcell

我想根据一些 if 条件改变它的高度。 我怎么能做到这一点?

我尝试在cellForRowAtIndexPath 中执行此操作 -

if (cell.newsFeedImage.image == NULL)
{
    NSLog(@"NULL");
    cell.uDisplayImage.frame = CGRectMake(20, 20, 20, 20);
}

出现日志消息,但框架永远不会改变。

请帮忙。

【问题讨论】:

标签: ios objective-c xcode uitableview ios7


【解决方案1】:

尝试在 heightForRowAtIndexPath 中执行此操作

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    CustomCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    if (cell.newsFeedImage.image == nil) {
        cell.uDisplayImage.frame = CGRectMake(20, 20, 20, 20);
    } 
    else return 40;
}

【讨论】:

    【解决方案2】:

    单元格的高度在tableView数据源方法中设置

    heightForRowAtIndexPath

    【讨论】:

    • 我知道,但我也想降低 uitableviecell 内内容视图的高度
    • 此方法是委托协议的一部分。您不使用它来设置高度,而是从中返回高度。
    【解决方案3】:

    比这要复杂一些。

    此问题已在此处详细回答:Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

    【讨论】:

      猜你喜欢
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多