【问题标题】:UITableViewAutomaticDimension not working in Xcode 6.3UITableViewAutomaticDimension 在 Xcode 6.3 中不起作用
【发布时间】:2015-04-10 15:20:03
【问题描述】:

我将我的 Xcode 和 Swift 1.2 一起更新到了 6.3,并进行了转换。

除了表格视图的动态行高外,一切正常。我有 3 个完全不同的表视图,所以它可能不是影响 bug 的其他因素。

我将所有表格视图设置为:

tableView.rowHeight = UITableViewAutomaticDimension

并且我所有的 xib 文件都得到了适当的约束。

有什么想法吗?

【问题讨论】:

  • 您添加了估计行高度吗?没有它就行不通

标签: xcode uitableview nslayoutconstraint xcode6.3


【解决方案1】:

我也简单地将 UITableViewAutomaticDimension 添加到estimatedrowforindexpath 中。您可以在 BEAM App(在“人员”类别下)查看它的工作原理。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}

【讨论】:

  • 是的,您应该提供一个估算值。此外,根据docs,使用回调而不是rowHeightestimatedRowHeight 属性会影响性能。您可以将rowHeight 设置为UITableViewAutomaticDimension,然后将estimatedRowHeight 设置为任意估计值。
【解决方案2】:

需要提供估计的行高。

除非必要,否则最好不要实现estimatedHeightForRowAtIndexPath:

estimatedRowHeight 更便宜,前提是您可以提出价值

    tableView.rowHeight = UITableViewAutomaticDimension
    tableView.estimatedRowHeight = 30 //Provide any appropriate value

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    • 2015-09-29
    • 1970-01-01
    • 2015-05-28
    • 2016-04-07
    • 2015-07-29
    • 2015-03-06
    相关资源
    最近更新 更多