How to add multiple UITableviewController to scroll view?

I want to make the profile viewcontroller something like Twitter. I believe that it contains 3 different child UITableviewController that continue to switch with segmented control. But when I browse my desktop viewController, it also scrolls the parent scroll view.

Can anyone explain how to achieve this behavior?

+5
source share
4 answers

I definitely know your problem. The problem is that Twitter is not an example, Snapchat however ....

You have a root view controller that includes UIScrollView (subclasses). Inside this subclass, you want to override gesture recognizers, for example ...

  -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if (gestureRecognizer.state != 0 && otherGestureRecognizer.state != 1) { return YES; } else { return NO; } 

}

Now you can scroll through tableViewCells and not drag all 4 directions at once.

+3
source
  • What you can do is make the UIScrollView a subview of the UIViewController, and then make the UICctainerView UIScrollView subcomponents.
  • But with the UIContainerView you can split the code and also use multiple UITableViewController .
  • Now add a UITableViewController and paste it into the UIContainerView.

Please look at the images below for a solution. Also check the structure in the document outline.

Using UIContainerView and UITableViewController


enter image description here


Hope this helps in solving your problem. Any questions please let me know.

+2
source

I also looked at this answer about three months ago. Previously, I tried to implement it using swapping TableView, but did not succeed. The swipe behavior between these child views is not the same; it looks weird. Finally, I end up using the "Pageview Controller". In addition to swipe gestures for switching between controllers, you can implement some buttons or a segmented control and call this function for navigation:

[self.pageViewController setViewControllers: viewControllers direction: direction animated: YES completion: ^ (BOOL finished) {
}];

+1
source

I'm sure this is only one table (or collection view) that simply switches cell types / cell data when one of the three buttons is pressed - why do you want to make it more complex?

You can also update all cells outside of your upper cells and remember that the scroll offset is a piece of cake compared to other solutions ...

+1
source

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


All Articles