Alex
Alex

Reputation: 1625

Suppress UITableViewCell delete button when using overriden setEditing method on iOS 7

I have a couple of UITableViewCell subclasses with overridden - (void)setEditing:(BOOL)editing animated:(BOOL)animated methods. In my implementation I have animations to show and hide custom views when the cell is swiped. On iOS 6 this works perfectly. My custom views are animated and the default delete button is not shown. However, on iOS 7 I get my custom views and animation as well as the default delete button. I am struggling to find a way to use my overridden setEditing:animated: without getting the system delete button.

In my UITableViewCell subclass I have overridden setEditing:animated: like this:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    if (editing) {
        CGFloat buttonWidth = _editButton.frame.size.width;
        [UIView animateWithDuration:0.3
                              delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                         animations: ^{
                             [_shareButtonXConst setConstant:buttonWidth * -3.0];
                             [self layoutIfNeeded];
                         }
                         completion:nil];
    } else {
        [UIView animateWithDuration:0.3
                              delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                         animations: ^{
                             [_shareButtonXConst setConstant:0.0];
                             [self layoutIfNeeded];
                         }
                         completion:nil];
    }
}

In my UIViewController I have:

- (void)loadView
{
    // ...

    UITableView *tableView = [[UITableView alloc] init];
    _tableView = tableView;
    [_tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [_tableView setBackgroundColor:[UIColor clearColor]];
    [_tableView setRowHeight:80.0];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];

    // ...
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

}

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

I have tinkered with this quite a bit and can't keep the delete button from appearing when I swipe. Has anyone else run into this issue? Thanks!

Upvotes: 1

Views: 541

Answers (1)

rmaddy
rmaddy

Reputation: 318894

If you don't want a delete button then you should return UITableViewCellEditingStyleNone in the editingStyleForRow... data source method.

Upvotes: 2

Related Questions