具有AutoLayout的UIScrollView内部的UITableView动态内容大小高度

Yos*_*far 1 objective-c uitableview uiscrollview ios autolayout

我有一个UIScrollView,在这个里面我有一个,在UIScrollViewUIView里面UIView有一些UITextField's,一些UILabel's,在底部有一个UITableView

我想要UITableView适合它的内容高度,UIView适合它的内容高度,UIScrollView适合它的内容高度。

UITableView我使用过程中它从添加/删除细胞的高度可能会改变。

使用它的最佳方法是什么AutoLayout

- UIViewController
-- UIView
--- UIScrollView
---- UIView
----- UILabel
----- UITextField
----- UITextView
----- UITableView (at the bottom of the superview)
Run Code Online (Sandbox Code Playgroud)

或在xib中:

在此处输入图片说明

Fog*_*ter 5

实施此操作的最佳方法是取消现有的层次结构并执行以下操作...

- UIViewController (or UITableViewController)
--- UITableView
----- UIView (as the tableView.tableHeaderView)
------- UILabel
------- UITextField
------- UITextView
----- Rest of the cells for the table view.
Run Code Online (Sandbox Code Playgroud)

tableView.tableHeaderView视图是单个(不可重复使用的,具体的)视图,位于表视图内容的顶部,并随表视图的内容滚动。它不会像节标题视图那样粘在屏幕顶部。

这将允许您删除滚动视图并将所有内容放置在表格视图中,并且仍然保持不变,因此不会更改用于填充单元格的方法。