views:

74

answers:

2

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?

+1  A: 

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;
}
jrtc27
this will stop the cell being able to be reordering, i just want to stop the deletion and allow the reordering.
Aran Mulholland
A: 
- (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.

Aran Mulholland