UITableViewCell prevent deletion
I am looking for a way of preventing the deleting of one of my cells. (No delete button should appear next to the cell when the table view is in editing mode.)
How can this be mad开发者_Go百科e possible?
Implement editingStyleForRowAtIndexPath and return UITableViewCellEditingStyleNone for that row:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == sss && indexPath.row == rrr)
return UITableViewCellEditingStyleNone;
else
return UITableViewCellEditingStyleDelete;
}
The accepted response works but is not the correct way to do it. There are two methods available: editingStyleForRowAtIndexPath
and canEditRowAtIndexPath
editingStyleForRowAtIndexPath: Use when there are multiple different editing styles in the table
canEditRowAtIndexPath: Use when some rows should edit and some should not.
Therefore the correct way to implement your table delegate is:
- (BOOL)tableView:(UITableView *)tableView
canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == sss && indexPath.row == rrr)
{
return NO;
}
return YES;
}
精彩评论