SimonTheDiver SimonTheDiver - 1 year ago 92
Objective-C Question

What is the correct way to remove the revealed swipe of a UITableViewCell when using editActionsForRowAtIndexPath:?

I have a

in which I am enabling swiping the cell to reveal options - in my case, 'share' and 'delete' options by using the following method:

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{

when a user swipes on a cell to reveal the options and then taps on
I put up a
with a confirmation. all is well and good if they say delete as i delete the object in my core data database and my
takes care of updating the

If the user declines to go through with the delete then the cell remains with the slide effect still revealing the options. I'd like it to go away. I know that
[tableView reloadData
] or, more efficiently, just reloading the one cell will solve the problem but is there a method call or property on the cell that I've missed that would do the job?

Answer Source

If you end editing on the table view here it will animate the cell back to its normal state.

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    [table setEditing:NO animated:YES];

If the table was in an editing state where it shows the delete button next to each cell, this will cause all of those delete buttons to go away, which may not be the behavior you want. In this case, you can immediately set the table view back to editing mode. The animation looks fine:

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    [table setEditing:NO animated:YES];
    if (yourWasPreviouslyEditingBoolean) {
        [table setEditing:YES animated:YES];

Note that you'll need to track this state yourself. Checking the table view's isEditing value will always return true here.

I haven't been able to find away to tell the cell directly to stop editing.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download