UITableViewController inside a UIScrollView with horizontal paging

this is the situation:

I need horizontal scrolling and tables in each page. This is something like a news application, it should display news from different categories when scrolling in the same horizontal direction, and within one category it should display about 30 news, scrollable vertically, of course.

I have successfully done what I need, but ...

I have the following script:

UINavigationController |__ UIViewController, which contains ScrollView and PageControl |__ UITableViewController, which holds data in rows, and is displayed inside parent, which is actually ScollView 

I know this is not an ideal solution, but at least it works. As a base, I used Apple code and a tutorial for PageScroll, found on this one. Instead of a simple viewController to add to ScrollView, I used TableViewController, so basically I add tableController.tableView to ScrollView.

I also know that adding tableViews inside a scrollview is like adding a car inside a truck and driving that car, but I could not find a smarter way to do the same.

So, I need your thoughts on how this can be done using some other approach. I use storyboards and iOS 5 for this, and everything seems (and looks) messy right now.

Thanks in advance, a lot.

+6
source share
2 answers

I did something similar a few months ago, and it was like this:

  • UINavigationController
    • UIViewController with UIScrollView
      • UIViewController with UITableView inside (I use this because I just hate UITablewViewController )

I followed the Apple documentation on creating custom containers . There is a great video in the WWDC 2011 video, if I'm not mistaken. I can proudly say that the code is really clean and clear.


Answer 1.0

On the one hand, did you manage to process the tableView table correctly without any hacks, or are you not using it?

No, in this case I did not do this, but I am sure that I could do it without any problems. You see, most problems arise when you just [self.view addSubView:newViewController.view]; . You just add a UIView , all rotation logic is handled using the newViewController, and not in the controller where the UIView will be.

Another thing is if I try to implement, say, a GridView or something like that, for the iPad, the orientation and animation become very ugly.

I implemented this in another project, and it was pretty easy to implement as soon as you understood what was going on:

  • I used a UIViewController with a UITableView so that I can get all the positive effects from dequeueReusableCellWithIdentifier: creating section headers, table headers and footers, etc. I just believe that no matter what I do with a UIScrollView a UITableView will always be more optimized. As UITableViewCell's I just used a holder with 3 squares, each of which was an image. (my application was a showcase of images).
+5
source

Source: https://habr.com/ru/post/919324/


All Articles