在故事板上将UITableView的rowHeight设置为UITableViewAutomaticDimension? [英] Set UITableView's rowHeight to UITableViewAutomaticDimension in storyboard?

查看:328
本文介绍了在故事板上将UITableView的rowHeight设置为UITableViewAutomaticDimension?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode 6中为iOS 8创建应用程序时,如何将UITableView的rowHeight设置为UITableViewAutomaticDimension?

When creating an app for iOS 8 in Xcode 6, how do I set my UITableView's rowHeight to UITableViewAutomaticDimension?

WWDC 2014会议226表和集合视图中的新增功能" 中,发言者说UITableViewAutomaticDimension是以编程方式创建的表视图的rowHeight的新默认值.但是,他还提到在会话期间,从xib/storyboard加载的表视图不是这种情况.

In WWDC 2014 Session 226 "What’s New in Table and Collection Views", the speaker says that UITableViewAutomaticDimension is the new default value for programmatically created table views' rowHeight. However, he also mention that at the time of the session this is not the case for table views loaded from a xib/storyboard.

现在Xcode 6 GM已经退出,我如何在情节提要中设置此值,而无需添加

Now that Xcode 6 GM is out, how do I set this value in the storyboard, without having to add

self.tableView.rowHeight = UITableViewAutomaticDimension;

在我的viewDidLoad中?

推荐答案

Xcode 11 +

从Xcode 11开始,Interface Builder现在在行高"输入附近具有一个自动"复选框.

Xcode 11+

Starting with Xcode 11, Interface Builder now has an "automatic" checkbox near the "Row Height" input.

发行说明所述:

现在,UITableView中的单元格可以使用画布中的自动布局"约束视图自动调整大小.要选择现有表格视图的行为,请在大小"检查器中为表格视图估计的项目大小启用自动",为单元格高度启用自动". (35735970)

Cells in a UITableView can now self size with Auto Layout constrained views in the canvas. To opt into the behavior for existing table views, enable "Automatic" for the table view estimated item size, and "Automatic" for cell’s height in the Size inspector. (35735970)

在情节提要中测试了不同的值之后,解决方案就是将默认的44pt值保留在 Row Height 中:

After testing different values in the storyboard, the solution is simply to keep the default 44pt value in Row Height:

这可能意味着您无法在情节提要中设置44pt的固定高度单元格.您必须以编程方式在viewDidLoad或其他位置进行设置.

What this probably means is that you can't have fixed height cells of 44pt anymore set in the storyboard. You'll have to set it programmatically in viewDidLoad or elsewhere.

最后,请注意,当前无法在情节提要中的任何位置设置estimatedRowHeight,并且,如果您未以编程方式进行设置,则默认为0. (欢迎编辑,如果您知道怎么做的话)

Finally, note that its currently not possible to set an estimatedRowHeight anywhere in storyboard, and that if you do not set it programmatically, it will default to 0. (edits welcome if you find out how to do this)

您可以通过记录viewDidLoad中的值来自己测试44pt行为:

You can test the 44pt behavior yourself by logging the values in viewDidLoad:

NSLog(@"%f", UITableViewAutomaticDimension);
NSLog(@"%f", self.tableView.rowHeight);

在行高"设置为"44"的情况下,会产生:

With Row Height set to 44 this produces:

-1.000000

-1.000000

-1.000000

-1.000000

将行高"设置为另一个值(此处为45pt):

With Row Height set to another value (here 45pt):

-1.000000

-1.000000

45.00000

这篇关于在故事板上将UITableView的rowHeight设置为UITableViewAutomaticDimension?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆