简体   繁体   English

从TableView到ScrollView-iOS

[英]TableView into ScrollView - iOS

I would like to insert a UITableView into a UIScrollView . 我想将UITableView插入UIScrollView To do this I added a ContainerView inside the UIScrollView and a UITableView linked to this ContainerView . 为此,我在UIScrollView内添加了一个ContainerView并链接到该ContainerViewUITableView

The result obtained in the storyboard is this : 在情节提要中获得的结果是:

http://i.stack.imgur.com/12hZz.jpg (Storyboard) http://i.stack.imgur.com/12hZz.jpg (故事板)

http://i.stack.imgur.com/AGY4L.jpg (Storyboard) http://i.stack.imgur.com/AGY4L.jpg (故事板)

When I launch the emulator the TableView is loaded correctly, but not with the result expected 当我启动模拟器时,TableView已正确加载,但预期的结果却不正确

http://i.stack.imgur.com/ebij9.gif (Animated GIF) http://i.stack.imgur.com/ebij9.gif (动画GIF)

http://i.stack.imgur.com/bEO8B.jpg (Wrong result) http://i.stack.imgur.com/bEO8B.jpg (错误的结果)

But instead what I wanted to to obtain is this: 但是我想获得的是:

http://i.stack.imgur.com/R7Zhb.jpg http://i.stack.imgur.com/R7Zhb.jpg

Is it possible? 可能吗? Could you tell me if the way to proceed is correct? 你能告诉我前进的方式是否正确? Thanks!! 谢谢!!

I have not enough reputation to post images and more than two links. 我没有足够的声誉来发布图像和两个以上的链接。 Sorry for my poor english. 对不起,我英语不好。

So what you have is close, but you need to set the size of the container view to the content size of the table view once it has loaded its data. 因此,您所拥有的已经很接近了,但是一旦加载了数据视图,就需要将容器视图的大小设置为表视图的内容大小。 Your other views around the content view then need to respond to the change in size so you don't get overlaps. 然后,围绕内容视图的其他视图需要响应大小的变化,以免重叠。

If you know the height of each row in the table and how many there are then it's easiest to calculate the hight required and set that as the size of the content view. 如果您知道表格中每一行的高度以及多少行,那么最简单的方法就是计算所需的高度并将其设置为内容视图的大小。 If you don't, or the height can change based on user choices or something like that, then you will need to do something more complicated which observes the content size of the table view and updates things when it changes. 如果您不这样做,或者高度可以根据用户的选择或类似的东西而改变,那么您将需要做一些更复杂的事情,即观察表格视图的内容大小并在表格视图更改时对其进行更新。

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

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