Reputation: 1378
I want to make a profile viewcontroller something similar to Twitter. I believe it contains 3 different child UITableviewController
which keeps switching by segmented control. But when I scroll my tableview of child viewController it scrolls the parent scroll view as well.
Can anybody explain how to achieve that behavior?
Upvotes: 5
Views: 1223
Reputation: 9346
I'm pretty sure it's just one table (or collection view) that just switches the cell types/cell data when you push one of the three buttons - why would you want to make it more complicated?
You can also only refresh all cells beyond your top cells, and remembering the scroll offset is a piece of cake compared to other solutions ...
Upvotes: 1
Reputation: 33
I also have looked at that answer for about three months ago. I used to tried to implement it with TableView paging but not success. The behavior of swipe between those child view not the same, it looks weird. Finally, I end up with using Page View Controller. Beside the swipe gesture to switch between the controllers, you can implemented the some buttons or segmented control and call this function to navigate:
[self.pageViewController setViewControllers:viewControllers direction:direction animated:YES completion:^(BOOL finished) {
}];
Upvotes: 1
Reputation:
I know your problem exactly. Problem is, Twitter is not an example, Snapchat however is....
You have a root View Controller that embeds a UIScrollView (Subclassed). Inside this subclass, you want to override the gesture recognizers like so...
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (gestureRecognizer.state != 0 && otherGestureRecognizer.state != 1)
{
return YES;
} else {
return NO;
}
}
Now you should be able to swipe tableViewCells and not drag in all 4 directions at once.
Upvotes: 3
Reputation: 2928
Please look at the images below for solution. Also check the structure in Document outline.
Using UIContainerView and UITableViewController
Hope it helps in solving your problem. Any queries please let me know.
Upvotes: 2