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

前端 未结 1 1500
猫巷女王i
猫巷女王i 2021-01-31 17:46

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-d

相关标签:
1条回答
  • 2021-01-31 18:13

    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];
    }
    
    0 讨论(0)
提交回复
热议问题