UIScrollView中的UITableView - 如何使视图滚动,而不是TableView本身? [英] UITableView in a UIScrollView - How to make the view scroll, but not the TableView in itself?

查看:64
本文介绍了UIScrollView中的UITableView - 如何使视图滚动,而不是TableView本身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,有一个带有UIScrollView的UIViewController。在视图的顶部有一个UIImageView,一些UILabels和其他东西。此外,还有一个UITableView,其内容是动态原型。我附上一张图片说清楚:

Imagine, there is a UIViewController with a UIScrollView in it. At the top of the view there is an UIImageView, some UILabels and other things. Furthermore, there is a UITableView which content is Dynamic Prototypes. I attach a picture to make it clear:

我在UITableView中没有静态数量的单元格,所以它可以滚动。我的问题如下:UITableView本身滚动但我想滚动整个视图。这样做的最佳可能性是什么?

I haven't got a static amount of cells in the UITableView so it could be scrollable. My problem is the following: the UITableView scrolls in itself but I want to scroll the whole View. What is the best possibility to do that?

我今天成立的可能的解决方案

Possible solutions I've founded today

1)第一件事是:我创建一个UITableViewController并声明一个标题部分,其中我以编程方式包含所有标签,图像等(我希望使用界面构建器...)

1) The first thing is: I create a UITableViewController and declare a header section in which I include all my labels, images etc. programmatically (I would love to use the interface builder for that...)

2)另一种解决方案是计算视图的高度。我尽力做到这一点 - 但是:没有成功。如果这是最好的方法:可以有人举个例子吗?

2) Another solution is to calculate the height of the view. I tried the best to do it like this way - but: without success. If this is the best way to do that: Can anybody give an example?

推荐答案

我会放弃 UIScrollView ,只需使用 UITableView 。您可以添加 UIView 对象作为 UITableView tableHeaderView >只需在Interface Builder中拖动它即可。现在,由于所有内容都是 UITableView 层次结构的一部分,因此所有内容都会按预期一起滚动。

I would ditch the UIScrollView and just use a UITableView. You can add a UIView object as the tableHeaderView of the UITableView just by dragging it in in Interface Builder. Now since everything is part of the UITableView hierarchy, everything will scroll together as expected.

这篇关于UIScrollView中的UITableView - 如何使视图滚动,而不是TableView本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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