Don't delete first row of a UITable
i have a UITable filled by a Model Core data, and i don't want that the user can delete the first row of a the table, so i do this:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
if (indexPath.row != 0) {
NSManagedObjectContext *context = [self.fet开发者_StackOverflow社区chedResultsController managedObjectContext];
[context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
[self saveContext];
}
// Delete the managed object for the given index path
}
}
i use this if (indexPath.row != 0) , it's right? i try and if i push delete in edit mode doesn't happen nothing...it's right or there is a better way?
This code will work but I think it is bad UI design. I don't think the user will understand that they can't delete the first row. More likely, they will think that the app has failed to enter edit mode.
The interface grammar teaches users to assume that all rows are identical and have identical behaviors. Having one special row forces the user to stop and think which row they have selected before they can predict what effect selecting edit will have. Making users have to keep track of app state like that is bad UI design.
If you have something special about the first row, you might want to put that data/function in a tableview header instead of row.
精彩评论