10

The swipe to delete functionality is not working in my table view. I have implemented the commitEditingStyle delegate and the Edit button in the navigation bar. Hence when the user clicks the edit button, the delete and add buttons show up appropriately. However, on swiping, the delete button does not appear and it seems like it doesn't recognise the swipe as a call for the setEditing method.

I then implemented willBeginEditingRowAtIndexPath and didEndEditingRwoAtIndexPath delegates as follows:

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

{
 NSLog(@"WILL BEGIN EDITING");

 [self.tableView setEditing:YES animated:YES];

}


-(void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath

{

[self.tableView setEditing:NO animated:YES];

}

However this does not have any effect either. What could be the possible issue? I have enabled multi-touch for the table view in the IB and each cell has an DetailDisclosureButton accessory.

7 Answers 7

7

For swipe-to-delete functionality, you have to implement

 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
        ; // Delete.
}

EDIT: I didn't read the question well enough.

I have noticed that to do a swipe drag in the simulator I have to press and pause for a second while it selects the cell, and only then can I swipe right successfully.

4
  • Yes i have implemented that. I have mentioned it above. I do not have access to a device right now and so am testing on the simulator. Could it be an issue with the simulator?
    – Nathan
    Commented Sep 17, 2010 at 14:29
  • So you did. Sorry. Check my edited answer just in case. The simulator is not 1-1 in touch behavior, especially speed. Commented Sep 17, 2010 at 14:37
  • Tried that on the simulator. Doesnt work. Also installed the app on an iPod Touch running 3.1.2. Swipe to delete doesnt work in that too. Very Puzzling. Im wondering if im missing out on some delegate implementation?
    – Nathan
    Commented Sep 17, 2010 at 14:43
  • Heres the thing. I started a new project and with a UITableViewController implementing only the commitEditingStyle delegate and the swipe to delete functionality worked perfectly. Need to see what is it in my code that is hampering this from working in my other project.
    – Nathan
    Commented Sep 17, 2010 at 15:21
6

You'll need to implement:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

With these three things you should be good to go. (I missed off the commitEditingStyle and it never worked.

1
  • 1
    I have given these 3 delegate methods but, not working.
    – Vineesh TP
    Commented Jul 4, 2014 at 6:46
5

If all other advices doesn't help try to check if you have pan gesture recognizer in your code. It will not work if you have things like this in some underlaying view.

2
  • Had the same issue, but it was with UITapGesture Commented May 28, 2015 at 11:09
  • You are a genius! I had a problem with a hard to drag slider for a few months and now with a tableviewCell, and the issue was a pan gesture recognizer in a framework I was using.
    – trusk
    Commented Mar 26, 2017 at 9:21
4

I was doing the following in the tableView:editingStyleForRowAtIndexPath: delegate method :-

if (self.editing == NO || !indexPath)
{   
    return UITableViewCellEditingStyleNone;
}

This was supposed to return editing style none if no indexPath was selected. For some reason whenever a swipe action was performed, this particular if condition was getting executed. On commenting the above code snippet, the swipe to delete action worked fine.

Thanks all for your help.

2

The key to make it work is to implement:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

And remember to put it inside "UITableViewDataSource" instead of "UITableViewDelegate"

0

did you implement the tableView:editingStyleForRowAtIndexPath: method and have it return UITableViewCellEditingStyleDelete

2
  • Yes i did. But there was something extra in it which caused this issue.
    – Nathan
    Commented Sep 17, 2010 at 15:42
  • glad i was able to get you looking at the right piece of code.. debugging issues like this are usually difficult Commented Sep 17, 2010 at 16:55
-2

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath delegate method also need to implement to work swipe functionality .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.