objective-cuitableviewuicolornsindexpathuitableviewrowaction

Table view cell background goes white when deleting a cell - iOS


I have an iOS app with a UITableView, I have noticed that the cell background colour flashes white when the user selects the Delete button.

In the editActionsForRowAtIndexPath method, I have created two cell buttons: Edit and Delete. The first button's style is set to UITableViewRowActionStyleNormal. however the second button's style is set to UITableViewRowActionStyleDestructive - I have noticed that this issue only occurs when then style is set to destructive. Does anyone know why this is happening?

Here is the method I am using to set the cell action buttons:

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // Create the table view cell edit buttons.
    UITableViewRowAction *editButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        
        // Edit the selected action.
        [self editAction:indexPath];
    }];
    editButton.backgroundColor = [UIColor blueColor];
    
    UITableViewRowAction *deleteButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        
        // Delete the selected action.
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }];
    
    return @[deleteButton, editButton];
}

The colour of the cell is normal when the user is scrolling, tapping it or when he/she selects the Edit button, but when they select the Delete button, the cell turns white as the deletion animation is occurring.

How can I fix this?


Solution

  • It turns out the issue I am experiencing, is due to an iOS bug. I found a solution here: https://stackoverflow.com/a/46649768/1598906

    [[UITableViewCell appearance] setBackgroundColor:[UIColor clearColor]];
    

    The above code is set in the App Delegate, it set the background color to clear, thus removing the white background view.