问题描述
这种情况:
我需要水平滚动,并且每页都需要表格视图.这就像新闻应用程序一样,它应该显示来自不同类别的新闻,当在一个水平方向上滚动时,应该显示一个类别中的大约30条新闻,并且可以垂直滚动.
I need horizontal scrolling, and table views inside every page. This is something like news app, it should display news from different categories, when scrolled in one horizontal direction, and inside one category it should display about 30 news, vertically scrollable, of course.
我已经成功完成了我所需要的,但是...
I have successfully done what i need, but...
我有以下情况:
UINavigationController
|__ UIViewController, which contains ScrollView and PageControl
|__ UITableViewController, which holds data in rows, and is displayed inside parent, which is actually ScollView
我知道这不是理想的解决方案,但至少可以奏效.作为基础,我使用了在链接.我不是使用简单的viewController添加到ScrollView,而是使用TableViewController,因此基本上是将tableController.tableView添加到ScrollView.
I know that this is not an ideal solution, but at least it works. As a base, i used Apple's code and tutorial for PageScroll found on this link. Instead of simple viewController to add to ScrollView, i used TableViewController, so basically i add tableController.tableView to the ScrollView.
我也知道,在scrollview中添加tableViews就像在卡车中添加一辆汽车并驾驶该汽车,但是我找不到更合理的方法来做同样的事情.
I know, also, that adding tableViews inside scrollview is sort of adding a car inside a truck and driving that car, but i couldn't find more reasonable way of doing same thing.
因此,我需要您考虑如何使用其他方法来完成此操作.为此,我使用情节提要和iOS 5,一切似乎(看起来)现在很混乱.
So, i need your thoughts about how this can be accomplished using some other approach. I use storyboarding and iOS 5 for this, and everything seems (and looks) messy right now.
非常感谢.
推荐答案
几个月前,我做了类似的事情,就像这样:
I did something similar a few months ago, and it was like this:
-
UINavigationController
-
UIViewController
和UIScrollView
-
UIViewController
,内部带有UITableView
(我之所以使用它,是因为我只是讨厌UITablewViewController
)
UINavigationController
UIViewController
with aUIScrollView
UIViewController
with aUITableView
inside (I use this because I simply hateUITablewViewController
)
我遵循了 Apple有关创建自定义容器的文档一个>.如果我没有记错的话,那么在WWDC 2011视频部分中有一个很棒的视频.我可以自豪地说代码非常干净而且易于理解.
I followed the Apple's documentation about creating custom containers. There is a great video about that in the WWDC 2011 video's section if I am not mistaken. I can proudly say that the code is really clean and simple to understand.
答案1.0
一件事是,您是否成功地获得了tableView的正确方向处理,而没有受到任何黑客攻击,或者您不使用它?
不,在这种情况下我没有,但是我确信我可以做到这一点而没有任何问题.您会看到,大多数问题都是在您
[self.view addSubView:newViewController.view];
时出现的.您只需添加UIView
,所有旋转逻辑都由newViewController处理,而不是在UIView
所在的控制器中.No, in this case I didn't, but I am sure I would have been able to do it without any problem. You see, most of the problems come when you just
[self.view addSubView:newViewController.view];
. You just add theUIView
, all the logic of the rotation is handled by the newViewController and not in the controller where theUIView
will be.另一件事是,如果我要尝试实现诸如GridView之类的功能,对于iPad,方向处理和动画将变得非常难看.
我在另一个项目中实现了该功能,一旦您了解发生了什么,就很容易实现:
I implemented this in another project and it was quite easy to implement once you understand what's going on:
- 我使用了
UIViewController
和UITableView
,因此我可以从dequeueReusableCellWithIdentifier:
中获得所有好处,创建节的标题,表的页眉和页脚等.我只是想知道无论我要做什么.UIScrollView
和UITableView
总是会不断优化.作为UITableViewCell's
,我只使用了一个3个正方形的支架,每个支架都是一幅图片. (我的应用是图片展示)
- I used a
UIViewController
with aUITableView
so I could get all the goodies from thedequeueReusableCellWithIdentifier:
, creation of section's titles, table's headers and footers, etc. I just figure that no matter what I would do with aUIScrollView
aUITableView
is always going to be more optimized. As theUITableViewCell's
I just used an holder with 3 squares, each one being a picture. (my application was a showcase of pictures)
这篇关于具有水平分页的UIScrollView内的UITableViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
-
-