Search code examples
iosuitableviewuipageviewcontrolleruiswipegesturerecognizer

How can I disable left and right swipe gestures on a UITableView


I have a UIPageViewController that has a large table in each content view. When I start swiping left or right outside of the UITableView the page turn effect is triggered. When I swipe left or right within the bounds of the UITableView the UIPageView controller doesn't seem to get the swipes.

I have turned off editing of table rows using:

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

It still seems the UITableView is stealing and holding onto the left and right swipes.


Solution

  • A UITableView is a subclass of UIScrollView, whose panGestureRecognizer steals touches (for scrolling). The tableView probably also adds its own SwipeGestureRecognizer.

    If you're on iOS 5, you can try and play around with the panGestureRecognizer, but you will probably have more luck just overlaying another view with its own gestureRecognizers, and scroll the tableView from there.