Set UITableView's rowHeight to UITableViewAutomaticDimension in storyboard?

故事扮演 提交于 2019-12-22 05:57:09

问题


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

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.

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

self.tableView.rowHeight = UITableViewAutomaticDimension;

in my viewDidLoad?


回答1:


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

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.

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)


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

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

With Row Height set to 44 this produces:

-1.000000

-1.000000

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

-1.000000

45.00000



来源:https://stackoverflow.com/questions/25888126/set-uitableviews-rowheight-to-uitableviewautomaticdimension-in-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!