UITableViewCellAccessoryView Custom Editing - Rejected Incorrectly

I have implemented a custom view of editing accessories as described in my answer to this question. For the most part, it works very well, but I noticed a little problem with it.

When I browse or select another row in the table view, my custom editing accessory does not decline. When using a standard editing accessory (delete button), a touch anywhere on the table is captured and used to delete an additional accessory - you can see it yourself in the built-in Notes application, for example, or anywhere else with the standard view of editing accessories.

This should be because I return UITableViewEditingStyleNone when I am in swipe mode. However, if I return to any other mode, my custom editing accessory is not displayed.

How can I return the functionality to the standard editing style, where touching anywhere in the table looks like a deflecting editing accessory?

The cell is not a subclass, but it is loaded from the nib file using a custom layout. The accessory view is part of the nib file and is connected via the editAccessoryView output.

I managed to accomplish half the effect achieved, keeping the index path of the line edited for editing and setting this cell from edit mode if another line is selected or scrolling starts in the table. However, I would like to do it right.

+2
source share
1 answer

I was able to solve this problem, but, unfortunately, it requires additional work and is not as simple as setting a couple of properties.

In my

 - (UITableViewCellEditingStyle)tableView:(UITableView *)_tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 

I am returning a UITableViewCellEditingStyleNone so that a custom editingAccessoryView . In this method, I also do this:

 self.tableView.scrollEnabled = NO; if(self.editingPath) { [[tableView cellForRowAtIndexPath:editingPath] setEditing:NO animated:YES]; } self.editingPath = indexPath; for (UITableViewCell *cell in [tableView visibleCells]) { cell.selectionStyle = UITableViewCellSelectionStyleNone; } 

This disables scrolling and then saves the indexPath , which we used for later use. If you draw another line by editing the line, it will turn off the first line and edit the second line, as apple applications do. I also set the selectionStyle cell for all visible UITableViewCellSelectionStyleNone cells. This reduces blue flickering when the user selects another cell during editing.

Next, we need to reject the accessoryView when another cell is involved. To do this, we implement this method:

 -(NSIndexPath *)tableView:(UITableView *)_tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(self.editingPath) { UITableViewCell *c = [tableView cellForRowAtIndexPath:self.editingPath]; [c setEditing:NO animated:YES]; self.tableView.scrollEnabled = YES; self.editingPath = nil; for (UITableViewCell *cell in [tableView visibleCells]) { cell.selectionStyle = UITableViewCellSelectionStyleBlue; } return nil; } return indexPath; } 

What does this mean when someone is going to click on a cell, if we are editing, then unedit this cell and do not return anything.

also for

 -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 

I am returning YES to allow editing on the cells that I want the user to be able to delete.

+2
source

All Articles