UITableViewController inside UIScrollView with Horizontal Paging

佐手、 提交于 2019-12-21 04:50:20

问题


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 a UIScrollView
      • UIViewController with a UITableView inside (I use this because I simply hate UITablewViewController)

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:

  1. I used a UIViewController with a UITableView so I could get all the goodies from the dequeueReusableCellWithIdentifier:, creation of section's titles, table's headers and footers, etc. I just figure that no matter what I would do with a UIScrollView a UITableView is always going to be more optimized. As the UITableViewCell'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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!