views:

116

answers:

3

Hi,

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

A: 

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.

Peter DeWeese
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
So you did. Sorry. Check my edited answer just in case. The simulator is not 1-1 in touch behavior, especially speed.
Peter DeWeese
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
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
A: 

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

Aaron Saunders
Yes i did. But there was something extra in it which caused this issue.
Nathan
check my answer above.
Nathan
glad i was able to get you looking at the right piece of code.. debugging issues like this are usually difficult
Aaron Saunders
+1  A: 

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.

Nathan