Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override swipe gesture on UITableView

I have a UITableView. I have added to this table a UIGestureRecognizer that looks for a swipe on a cell, and enables editing on that table if it detects a swipe. When I swipe right, it does indeed enable editing on the table. However, when I swipe left, I get the default red delete button appear on the right side of the cell. How can I disable this default behavior, and make it so that if I swipe left OR right, I get editing on either way?

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
    foldersTable.editing=YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIGestureRecognizer *recognizer;
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [foldersTable addGestureRecognizer:recognizer];
    [recognizer release];

}
like image 329
bitmoe Avatar asked Sep 03 '11 21:09

bitmoe


2 Answers

Just return UITableViewCellEditingStyleNone in your tableView:editingStyleForRowAtIndexPath: method.

like image 158
Marcelo Alves Avatar answered Nov 11 '22 20:11

Marcelo Alves


There is a direction property on UISwipeGestureRecognizer. You can set that to both right and left swipes:

recognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
like image 24
Benjamin Mayo Avatar answered Nov 11 '22 20:11

Benjamin Mayo