UITableViewAutomaticDimension 在 Xcode 6.3 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29565078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:57:16  来源:igfitidea点击:

UITableViewAutomaticDimension not working in Xcode 6.3

xcodeuitableviewnslayoutconstraintxcode6.3

提问by Stefan Salatic

I updated my Xcode to 6.3 along with Swift 1.2, and I made the transition.

我将我的 Xcode 和 Swift 1.2 一起更新到 6.3,然后我完成了转换。

Everything works except dynamic row height for table view. I have those on 3 completely different table views, so it probably isn't something else influencing the bug.

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

I set all of the table views to:

我将所有表视图设置为:

tableView.rowHeight = UITableViewAutomaticDimension

and all of my xib files are properly constrained.

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

Any ideas?

有任何想法吗?

回答by Ken

I simply added UITableViewAutomaticDimension to estimatedrowforindexpath as well. You can see how it works on the BEAM App(under 'people' category).

我也只是将 UITableViewAutomaticDimension 添加到estimatedrowforindexpath 中。您可以在BEAM 应用程序(在“人员”类别下)查看它是如何工作的。

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

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

回答by user1046037

Estimated row height needs to be provided.

需要提供估计的行高。

It is better not to implement estimatedHeightForRowAtIndexPath:unless necessary.

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

estimatedRowHeightis cheaper provided you can come up with a value

estimatedRowHeight如果您能提出一个价值,则更便宜

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