Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get swipe-to-delete working when tableView's allowsMultipleSelectionDuringEditing property is YES?

In iOS 5, if I set allowsMultipleSelectionDuringEditing to YES on a UITableView then swipe-to-delete no longer works. The built-in Mail app supports both swipe-to-delete and multiple selections in edit mode, and I'd like to do likewise. How do I achieve this?

like image 810
Simon Whitaker Avatar asked Mar 13 '12 11:03

Simon Whitaker


1 Answers

The trick is to set allowsMultipleSelectionDuringEditing to YES on entering edit mode and set it back to NO on exiting edit mode. This way, both swipe-to-delete and multiple selections in edit mode work.

If you've subclassed UITableViewController (which you probably have), then you can simply do this:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {     // Set allowsMultipleSelectionDuringEditing to YES only while     // editing. This gives us the golden combination of swipe-to-delete     // while out of edit mode and multiple selections while in it.     self.tableView.allowsMultipleSelectionDuringEditing = editing;      [super setEditing:editing animated:animated]; } 
like image 147
Simon Whitaker Avatar answered Oct 08 '22 03:10

Simon Whitaker