简体   繁体   English

Xcode 5自动布局-嵌入式表

[英]Xcode 5 Auto Layout - Embedded Tables

I have a UIScrollView with several UITableView s embedded in it. 我有一个UIScrollView ,其中嵌入了几个UITableView I want to allow each table to expand its height as much as is needed to display all of its cells. 我想允许每个表扩展其高度,以显示其所有单元格所需的高度。 The scroll view's frame takes up the whole screen, so its contentSize.height need to expand to fit the biggest table (which I think is the default behavior, but I mention it just in case I'm incorrect). 滚动视图的框架占据了整个屏幕,因此需要扩展它的contentSize.height以适合最大的表(我认为这是默认行为,但为防止我不正确,我会提到它)。 Can this all be done on my storyboard? 这一切都可以在我的故事板上完成吗? Or if I will need to add code to do it, I found this tutorial , but it's for iOS 6 - has any of the code for this constraint stuff changed for iOS 7? 或者,如果我需要添加代码来执行此操作,我找到了本教程 ,但该教程适用于iOS 6-是否已针对iOS 7更改了此约束条件的任何代码?

If you know in advance how much room each table takes up you can do it purely in your storyboard, but because each UITableView is also a scrollview the default behavior of a UITableView is to fill the assigned size with content and scroll if there is overflow. 如果您事先知道每个表占用了多少空间,则可以纯粹在情节提要中完成它,但是由于每个UITableView也是滚动视图,因此UITableView的默认行为是用内容填充分配的大小并在溢出时滚动。

If you do not know the height of the tables at design time, you will need to set them at run time. 如果在设计时不知道表格的高度,则需要在运行时进行设置。 See Autolayout a UIScrollView to fit content including subviews and grouped tables for an example, the short answer is to add a height constraint to your table, drag it into your controller as an outlet, and then set the height when you know it. 有关示例,请参见自动布局UIScrollView以适合包括子视图和分组表的内容 ,简单的答案是在表中添加高度限制,将其拖动到控制器中作为插座,然后在知道高度时设置高度。

It can be done both ways.Manually moving UI elements through code(mentioning locations) and overriding it in did rotate or through mentioning constraints in auto layout. 可以通过两种方式完成。通过代码(提及位置)手动移动UI元素并覆盖它确实旋转了,或者通过在自动布局中提到了约束。

This link http://www.doubleencore.com/2013/09/auto-layout-updates-in-ios-7/ provides details of ios7 auto layout . 此链接http://www.doubleencore.com/2013/09/auto-layout-updates-in-ios-7/提供了ios7自动布局的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM