Get Swipe to Delete on UITableView to Work With UIPanGestureRecognizer

ios, objective-c, uipangesturerecognizer, uitableview

Solution

From the document:

If a gesture recognizer recognizes its gesture, the remaining touches for the view are cancelled.

Your `UIPanGestureRecognizer` recognizes the swipe gesture first, so your `UITableView` does not receive touches anymore.

To make the table view receives touch simultaneously with the gesture recognizer, add this to the gesture recognizer's delegate:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

Problem

I have a UIPanGuestureRecognizer added to the entire view using this code: ``` UIPanGestureRecognizer *pgr = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; [[self view] addGestureRecognizer:pgr]; ``` Within the main view I have a UITableView which has this code to enable the swipe to delete feature: ``` - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"RUNNING2"); return UITableViewCellEditingStyleDelete; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row >= _firstEditableCell && _firstEditableCell != -1) NSLog(@"RUNNING1"); return YES; else return NO; } ``` Only `RUNNING1` is printed to the log and the Delete button does not show up. I believe the reason for this is the UIPanGestureRecognizer, but I am not sure. If this is correct how should I go about fixing this. If this is not correct please provide the cause and fix. Thanks.

Original source