问题
this is the situation:
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...
I have following scenario:
UINavigationController
|__ UIViewController, which contains ScrollView and PageControl
|__ UITableViewController, which holds data in rows, and is displayed inside parent, which is actually ScollView
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.
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.
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.
Thanks in advance, a lot.
回答1:
I did something similar a few months ago, and it was like this:
UINavigationController
UIViewController
with aUIScrollView
UIViewController
with aUITableView
inside (I use this because I simply hateUITablewViewController
)
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.
Answer 1.0
The one thing is, did you managed to get proper orientation handling of the tableView, without any hack, or you don't use it?
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 the UIView
, all the logic of the rotation is handled by the newViewController and not in the controller where the UIView
will be.
The other thing is, if i'm gonna try to implement, say, GridView or something like that, for iPad, orientation handling and animations become very ugly.
I implemented this in another project and it was quite easy to implement once you understand what's going on:
- 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)
回答2:
http://www.raywenderlich.com/4680/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-1
Chk out above link
来源:https://stackoverflow.com/questions/11262047/uitableviewcontroller-inside-uiscrollview-with-horizontal-paging