5
votes

This is similar to questions that are asking how to swipe/delete without confirmation:

UITableView swipe to delete with no confirmation

My tableview has cells with UITableViewCellEditingStyleDelete set. When the tableview is in editing mode, the cells display a red circle icon with a '-' inside. To delete the cell, the user taps the red circle, and a Delete button appears. The user must then tap Delete which triggers tableView:commitEditingStyle:forRowAtIndexPath:.

Some of my rows support UITableViewCellEditingStyleInsert. In this scenario the cells display a green circle icon with a '+' inside. Tapping the circle invokes tableView:commitEditingStyle:forRowAtIndexPath: immediately.

I'd like to have tableView:commitEditingStyle:forRowAtIndexPath: invoked immediately when the user taps the initial red-circle icon. That is, no delete-button step.

Any ideas?

Is there a way to provide custom editing controls that slide in from the left like delete/insert? If so, perhaps I could use this mechanism?

1

1 Answers

3
votes

I came up with one solution, but it risks rejection. (Does checking for an undocumented class by classname constitute a sdk-agreement violation?)

Perhaps someone can improve on this?

Basically, in the context of my custom UITableViewCell, I watch for the delete button (not a UIButton, unfortunately) to be added, then invoke it's UIControlEventTouchUpInside action. With a bit of delay so the animations work out:

- (void) addSubview:(UIView *)view
{
    if ([NSStringFromClass([view class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) 
    {

        UIControl* c = (UIControl*)view;

        NSArray* actions = [c actionsForTarget: self forControlEvent: UIControlEventTouchUpInside];

        [self performSelector: NSSelectorFromString( [actions lastObject] ) withObject: view afterDelay: .25];

        return;
    }

    [super addSubview: view];
}