UIscrollView中UITableView的内容大小问题

ksc*_*ler 6 iphone interface-builder scrollview uitableview contentsize

我实际上用界面构建器创建了UIScrollView一个UITableView内部.我设置了我的内容大小UIScrollView:

scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
Run Code Online (Sandbox Code Playgroud)

然后我将文件的所有者视图设置为 UIScrollView

我创建了一个IBOutlet UITableView并在界面构建器中设置它.

加载视图时.它显示我的正确内容大小UIScrollView.但它没有显示我的正确内容大小UITableView.此外,当我更改我的内容大小时UIScrollView,它会更改我的内容大小,UITableView就好像两个内容大小都相关.

任何人都知道如何保持我在界面构建器中设置的表视图的内容大小?

DBD*_*DBD 12

A UITableView是一个UIScrollView.很少有时候嵌入一个UITableView内部是有用的UIScrollView.

假设你真的想要这个,你需要在某个地方做以下事情.在填充表视图之后,可能在您UIViewController的方法中viewDidAppear:或类似的地方.

// Set the size of your table to be the size of it's contents 
// (since the outer scroll view will handle the scrolling).
CGRect tableFrame = tableView.frame;
tableFrame.size.height = tableView.contentSize.height;
tableFrame.size.width = tableView.contentSize.width; // if you would allow horiz scrolling
tableView.frame = tableFrame;

// Set the content size of your scroll view to be the content size of your 
// table view + whatever else you have in the scroll view.
// For the purposes of this example, I'm assuming the table view is in there alone.
scrollView.contentSize = tableView.contentSize;
Run Code Online (Sandbox Code Playgroud)