UITableViewCell: enable selective deletion

I have a table view and you want to allow reordering of all cells, however there are certain cells that I do not want to be able to delete. when the UiTableView is placed in delete mode, I don’t want the red “-” button to appear on the left side, and I don’t want the swipe gestures to call the “Delete” button of these cells, but I wanted it to happen for others, Any ideas?

+4
source share
2 answers
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ //if we cant delete the object represented at the index path if ([[tableViewObjectsArray objectAtIndex:indexPath.row] canBeDeleted] == NO){ return UITableViewCellEditingStyleNone; } //otherwise allow the deletion else{ return UITableViewCellEditingStyleDelete; } } 

Of course, this leaves an empty space where the “-" button should be, but this does not allow deleting. And also does not allow you to remove wipes.

+7
source

implementation of

 // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } 
+2
source

Source: https://habr.com/ru/post/1311283/


All Articles