Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swipe to Delete not working

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.

like image 455
Nathan Avatar asked Sep 17 '10 14:09

Nathan


People also ask

How do I change swipe to delete?

Select Swipe Options. Select Swipe Right or Swipe Left. Assign one of the follow preferred actions: Delete, Mark as Read, Mark as Unread, Flag, and Archive.

How do I make my IPAD swipe to delete Mail?

If you navigate to Settings > Mail > Swipe Options, you can select an option for Swipe Left and Swipe Right.


3 Answers

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"

like image 88
Val Avatar answered Oct 04 '22 08:10

Val


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.

like image 41
Jindřich Skeldal Avatar answered Oct 04 '22 07:10

Jindřich Skeldal


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.

like image 41
Scott McKenzie Avatar answered Oct 04 '22 07:10

Scott McKenzie