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?
Asked
Active
Viewed 4,479 times
1
-
refer http://stackoverflow.com/questions/4604296/uigesturerecognizer-and-uitableviewcell-issue – Nikunj Jadav Sep 14 '11 at 13:15
-
1Thanx nikunj you helped me :) – Mashhadi Sep 19 '11 at 09:55
2 Answers
1
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];

Valeriy Van
- 1,851
- 16
- 19
-
1I am a newbe so please don't mind of my silly questions. please give me some more detail. cz it is not detecting swipe – Mashhadi Sep 14 '11 at 14:36
-
1try changing the 21 to a 1. That means you are needing 21 fingers on it doesn't it? – user2277872 Jun 17 '13 at 05:00
0
You have to implement two delegate method.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
and other method where you have to perform you editing or deleting code.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//write delete code.
[arry removeObjectAtIndex:indexPath.row];
[Table reloadData];
}
}

Mobile App Dev
- 1,824
- 3
- 20
- 45