Add swipe gesture to UITableView

maxhud picture maxhud · Nov 16, 2013 · Viewed 10k times · Source

How would I make it so that one gesture anywhere on a UITableView would do something?

Not just within one cell, but anywhere on the screen (a horizontal swipe)?

Answer

Vizllx picture Vizllx · Nov 16, 2013
- (void)viewDidLoad
{
    [super viewDidLoad];
    UISwipeGestureRecognizer *recognizer;
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    //There is a direction property on UISwipeGestureRecognizer. You can set that to both right and left swipes
    recognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
    [tableView addGestureRecognizer:recognizer];
    [recognizer release];

}

Finally

Just return UITableViewCellEditingStyleNone in your tableView:editingStyleForRowAtIndexPath: method.