3

I am working on a "user profile" section of an iOS 7 iPad application. In this area, we walk the user through a series of pages where they enter information about themselves - biographical information, family, contact info, etc. The way I've set this up is through a UIPageViewController, where each page of the user profile is its own UIViewController (with a UIScrollView, since each page can get long), so that the user can smoothly swipe between pages as they walk through it. On a few of the pages, we also have UITableViews (not taking up the entire screen, since this is an iPad app and not an iPhone app) for the user to add information. So the overall simplified view hierarchy on these pages would be:

UIPageViewController
UIScrollView
UITableView

I would like the user to be able to use the swipe-to-delete gesture to delete cells from the UITableView. Unfortunately, the pan gesture which activates the swipe-to-delete in a UITableView is being picked up by the UIPageViewController and scrolls to the next page instead of showing the delete button. Getting the delete button to show is very inconsistent - probably 9 times out of 10 it will scroll to the next page instead.

Ideally, I would access the pan gesture recognizer of the UIPageViewController and try to set up some dependency between it and the UITableView's pan gesture recognizer, or have some logic for the UIPageViewController's gesture recognizer not to fire within the area of the UITableViewController, or something. However, due to this phenomenon (whether bug or feature), I cannot access the gesture recognizers of the UIPageViewController, so I can't do things like set their delegate and override methods like gestureRecognizerShouldBegin. I also can't get the gesture recognizers of the UIPageViewController's view.

Does anyone have any ideas for how to circumvent this issue?

Community
  • 1
  • 1
UberJason
  • 3,063
  • 2
  • 25
  • 50

1 Answers1

1

I don't know how to reliably get to the page vcs gesture recognizers. The only idea I can give is how to temporarily enable/disable them. I can't vouch for it's admissibility because I haven't submitted the app, but it looks kosher to me:

- (void)setScrollEnabled:(BOOL)enabled onPageViewController:(UIPageViewController *)pvc {
    for (UIScrollView *view in pvc.view.subviews) {
        if ([view isKindOfClass:[UIScrollView self]]) {
            view.scrollEnabled = enabled;
        }
    }
}

If acceptable, it's a good candidate for a category method on UIPageViewController.

danh
  • 62,181
  • 10
  • 95
  • 136
  • Unfortunately, since each individual page view controller has a UIScrollView in it, I think this method would also catch those scrollviews and prevent them from scrolling, right? Since those individual pages are subviews of the UIPageViewController. And that would be undesired. – UberJason Feb 24 '14 at 15:51
  • No, there's a scroll view in the pvc that sits under the contained vc's views (the point of the loop is to not depend on any other subview of the pvc view). The loop only digs one level deep. But I think my answer is insufficient for you anyway, because it really doesn't solve the need for selective use of the page scrolling gesture. I'm not sure your problem is solvable without access to the page view controller's gr. – danh Feb 24 '14 at 15:58
  • I see, and thanks for the clarification. Unfortunately I think you're right, and this won't quite solve the problem, but it's a good tip to keep in mind if I ever need to do this. – UberJason Feb 24 '14 at 19:54