Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable the delete operation for certain row in a UITableView?

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

like image 654
arachide Avatar asked Jun 07 '10 06:06

arachide


People also ask

How to delete cell UITableView?

So, to remove a cell from a table view you first remove it from your data source, then you call deleteRows(at:) on your table view, providing it with an array of index paths that should be zapped. You can create index paths yourself, you just need a section and row number.

How to delete UITableViewcell in swift?

When you want to handle deleting, you have to do three things: first, check that it's a delete that's happening and not an insert (this is down to how you use the UI); second, delete the item from the data source you used to build the table; and third, call deleteRows(at:) on your table view.


2 Answers

Implement the -tableView:canEditRowAtIndexPath: method in your data source. Return NO for those rows.

like image 195
kennytm Avatar answered Sep 19 '22 11:09

kennytm


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; 
}
like image 41
Charlie Wu Avatar answered Sep 21 '22 11:09

Charlie Wu