After scrolling into a UITableViewCell in a UITableView, how do I programmatically close the swipes?

I activate scrolling to the left in the row to show the action. After clicking on the action, I want the open open table cell to close. How should I do it?

I tried cell.setEditing(false, animated:true)

, but the edit setting doesn't close the swipe.

+3


source to share


1 answer


Note. I don't have enough reputation to comment on your question, so I would have to make some assumptions about your implementation.

If you are trying to close a cell in tableView:commitEditingStyle:forRowAtIndexPath:

, you can try this:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        // remove delete button only after short delay
        [self performSelector:@selector(hideDeleteButton:) withObject:nil afterDelay:0.1];
    }
}

- (void)hideDeleteButton:(id)obj
{
    [self.tableView setEditing:NO animated:YES];
}

      



The reason for using performSelector:withObject:afterDelay:

is a note in the iOS Spreadsheet Programming Guide

Note. The data source should not call setEditing: animated: from within its implementation tableView: commitEditingStyle: forRowAtIndexPath :. If for some reason it should, it should call it after a delay using the performSelector: withObject: afterDelay: function.

This was all heavily inspired by the following answer: fooobar.com/questions/2173973 / ...

+7


source







All Articles