Ios – Disable Swipe-to-Delete Gesture in UITableView

cocoa-touchiosobjective cuitableview

Is it possible to disable the 'swipe-to-delete' gesture for a row/cell in a tableView? If so, how do you do it? The cell should still be editable in EDIT mode, but the swipe-to-delete gesture should be disabled.

Best Answer

Here's what to do:

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    // Detemine if it's in editing mode
    if (self.tableView.editing) {
        return UITableViewCellEditingStyleDelete;
    }
    return UITableViewCellEditingStyleNone;
}

You still need tableView:commitEditingStyle:forRowAtIndexPath: to animate the deletion.

This is a much cleaner solution than iBrad Apps' solution, since you can use the default self.editButtonItem instead of a custom button.

Link: UITableView disable swipe to delete, but still have delete in Edit mode?