UberJason
UberJason

Reputation: 3163

iOS 7 iPad: UITableView swipe-to-delete in a UIPageViewController (conflicting gesture recognizers)

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?

Upvotes: 3

Views: 1199

Answers (1)

danh
danh

Reputation: 62676

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.

Upvotes: 1

Related Questions