Search code examples
iphoneswipeuiswipegesturerecognizer

How to impliment UISwipeGestureRecognizer on UITableView cell?


How can i add swipe gesture in my table view cell? i am using custom cell in tableview and i have to delete that row from table so please guide me how can i use this swipe gesture in table view?


Solution

  • Absolutely the same as in any other view. Insert this code either in your custom cell's init or in cellForRowAtIndexPath method of your UITableViewDataSource delegate.

    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:myTableViewController action:@selector(removeCell:)];
    recognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    recognizer.numberOfTouchesRequired = 1;
    [self addGestureRecognizer:recognizer];
    [recognizer release];