Reputation: 67
Going through the BigNerdRanch's guide to iOS and one of the tasks is to add a "No More Items" cell to the bottom of a list of items in a UITableView. So, I added the item to the bottom, but I want to make it so that I cannot delete it and I cannot reorder it.
I can set the reordering by doing: canMoveRowAtIndexSource to NO. However, the delete button still appears. I know I can reject a delete confirmation for the rows that I don't want removed, but I don't want the delete buttons to appear at all.
I know I can get rid of the delete button by setting canEditRowAtIndexPath to NO. However, when i go into edit mode, those rows look wonky because they're no longer indented.
It looks like I can indent the content of a cell, but not a cell itself. Is that right?
What would be the best approach to this problem? Even the name of a method would be really helpful.
Upvotes: 0
Views: 1081
Reputation: 9722
What I did was use the editingStyleForRowAtIndexPath and check there if cell were deletable, like this:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(... can delete ...)
{
return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}
Upvotes: 1