Question

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)?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top