UIscrollView中UITableView的内容大小问题 [英] Content size issue for UITableView in UIscrollView

查看:131
本文介绍了UIscrollView中UITableView的内容大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上在界面构建器中创建了一个带有 UITableView UIScrollView 。我使用以下内容设置 UIScrollView 的内容大小:

I actually create a UIScrollView with a UITableView inside it with interface builder. I set the content size of my UIScrollView with:

scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);

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

and I set my file's owner view to the UIScrollView

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

I created an IBOutlet UITableView and I set it in the interface builder.

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

When the view is loaded. it displays the correct content size for my UIScrollView. But it doesn't display the correct content size for my UITableView. Besides when I change the content size of my UIScrollView, it changes the content size of my UITableView as if both content size were related.

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

Anyone knows how can I keep the content size of my table view that I set in the interface builder?

推荐答案

UITableView UIScrollView 。在 UIScrollView 中嵌入 UITableView 非常有用。

A UITableView is a UIScrollView. There are very few times when it would be useful to embed a UITableView inside a UIScrollView.

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

Assuming you really do want this, you'll need to do the following somewhere. Probably in your UIViewController in methods like viewDidAppear: or somewhere you after you populate the table view.

// 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;

这篇关于UIscrollView中UITableView的内容大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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