iOS Development Journal

Tips and Tricks Learned the Hard Way

Swipe to Delete With Multiple Selection

The Problem:

(Solution found via StackOverflow)

You have a UITableView that has allowsMultipleSelectionDuringEditing set to YES, since you’d like to allows for bulk deletes or other actions. Prior to adding bulk editing support you also could perform a swipe-to-delete when not in editing mode. However, you’ve just noticed that swipe-to-delete no longer works. And you want both.

The Solution:

So it turns out that you can’t have allowsMultipleSelectionDuringEditing active and have swipe-to-delete work at the same time. So what you need to do is only enable allowsMultipleSelectionDuringEditing when the table view is in editing mode.

This is achieved by a simple addition to your UITableViewController sub-class.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    self.tableView.allowsMultipleSelectionDuringEditing = editing;

And with that swipe-to-delete works, and so does bulk editing!