Reputation: 8066
I know about using setEditing:
to enable the editing mode of UITableView.
But I prefer to disable the operation for some certain rows (enable other rows).
Is it possible?
Thanks,
interdev
Upvotes: 19
Views: 12135
Reputation: 56
Based on your question, I understand that you want to just hide the delete button from appearing on the 1st row. please set tableview editing to yes and add the below code
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row==0)
{
return NO;
}
return YES;
}
Upvotes: 3
Reputation: 7757
this post sum it up perfectly, Is there any way to hide "-" (Delete) button while editing UITableView
in case you don't want to read the post the gist is on the row you don't want to delete but want to allow move row: set edit style for row to UITableViewCellEditingStyleNone
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
Upvotes: 10
Reputation: 111
Using canEditRowAtIndexPath will not allow the row to align with other cells in grouped style. which can look bad.
I use UITableViewCellEditingStyleNone
, for the rows which you do not want to show the edit control (minus/plus button), put this in your
(UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{}
Upvotes: 9
Reputation: 523294
Implement the -tableView:canEditRowAtIndexPath:
method in your data source. Return NO
for those rows.
Upvotes: 36