I have a table view and want to allow reordering of all cells, however there are certain cells that I do not want to be allowed to be deleted. when the UiTableView is put into deletion mode I do not want the red '-' button to appear on the left hand side, and do not want the swipe gesture to bring up the Delete button of these cells but want it to happen for the others. Any ideas?
- (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 it does not allow deletion. And also does not allow the swipe deletion either.
implement:
// 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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With