maxhud maxhud - 5 months ago 68
iOS Question

Add swipe gesture to UITableView

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
- (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.

Comments