Add swipe gesture to UITableView
10,010
Solution 1
- (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.
Solution 2
If you want to make it dead simple using the interface builder you can apply the gesture on a ViewController that contains only the TableView and show that ViewController inside a container.
Author by
Max Hudson
Updated on June 04, 2022Comments
-
Max Hudson almost 2 years
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)?