Want to present the delete button on right-to-left swipe in UITableView
iphone, objective-c, uitableview
Solution
This might work. Put this code in `awakeFromNib` or `init`:
UISwipeGestureRecognizer *swipeDelete = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeDelete:)];
[swipeDelete setDirection: UISwipeGestureRecognizerDirectionLeft];
[yourTableView addGestureRecognizer:swipeDelete];
then in `handleSwipeDelete` organize your cell and show delete button. You will probably need to handle cell state and change it on swipeLeft/swipeRight.
Problem
``` - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewCellEditingStyleDelete; } - (void)tableView:(UITableView *)tableView commitEditingStyle(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if(editingStyle == UITableViewCellEditingStyleDelete){ //[theSimpsons removeObjectAtIndex:indexPath.row]; NSString *time = [[arrayList objectAtIndex:indexPath.row] objectForKey:@"TIME"]; NSString *date= [[arrayList objectAtIndex:indexPath.row] objectForKey:@"DATE"]; DBManager *dbm = [[DBManager alloc] init]; [dbm initiallzeDatabase]; [dbm deleteItemAtIndexPath:time :date]; //arrayList = [dbm getParkResults]; //[parkTableView reloadData]; [arrayList removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } ``` I have used the above code in my app. The editing part works fine, but the thing is, the delete button appears only when we swipe from left-to-right on a cell. Now i have a menu that opens on left-to-right swipe like Facebook. So how can i make sure that the delete button appears when the user swipes from right-to-left.