I was able to solve this, but sadly it requires additional legwork and isnt just as simple as setting a couple properties.
In my
- (UITableViewCellEditingStyle)tableView:(UITableView *)_tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
method I return UITableViewCellEditingStyleNone
so that my custom editingAccessoryView
will show up. 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, then stores the indexPath
we swiped on for later use. If you swipe another row, while editing a row, it will unedit the first row and edit the second row, which is how apple apps behave. I also set the cell selectionStyle
on all visible cells to UITableViewCellSelectionStyleNone
. This reduces the blue flicker when the user selects another cell while your currently editing one.
Next we need to dismiss the accessoryView
when another cell is tapped. To do that 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 this does is when someone is about to click on a cell, if we are editing then unedit that cell and return nothing.
also for
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
I return YES
, to enable editing on the cells I want the user to be able to delete.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…