maxhud maxhud -5 years ago 279
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 Source
- (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];



Just return UITableViewCellEditingStyleNone in your tableView:editingStyleForRowAtIndexPath: method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download