UITableView allows MultipleSelectionDuringEditing - not to display the edited circle for some cells

I am trying to delete multiple rows in a UITableView by setting allowsMultipleSelectionDuringEditing to YES . It all works well; the circle shows on the left side.

However, for some cells, I do not want the circle on the left side to rise. How can I do it? I tried cell.selectionStyle = UITableViewCellSelectionStyleNone while editing, and this did not work.

Any clues?

+4
source share
3 answers

To disable multiple rows from multiple selection options, you should use tableView:shouldIndentWhileEditingRowAtIndexPath: mixed with cell.selectionStyle = UITableViewCellSelectionStyleNone .

Here is an example from my code:

 - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath*)indexPath { if (indexPath.row < 4) { return YES; } else { return NO; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // (...) configure cell if (indexPath.row < 4) { cell.selectionStyle = UITableViewCellSelectionStyleBlue; } else { cell.selectionStyle = UITableViewCellSelectionStyleNone; } } 
+2
source

First use the following settings:

 self.tableView.allowsMultipleSelectionDuringEditing = true self.tableView.setEditing(true, animated: false) 

And we implement the following delegate methods:

 func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return self.shouldAllowSelectionAt(indexPath) } func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool { return self.shouldAllowSelectionAt(indexPath) } func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { if self.shouldAllowSelectionAt(indexPath) { return indexPath } return nil } 

shouldAllowSelectionAt is my private method that contains logic about which row to select

0
source

Have you tried to implement the tableView:editingStyleForRowAtIndexPath: UITableViewDelegate method and return UITableViewCellEditingStyleNone for cells that you do not want to display with the delete control?

-1
source

All Articles