views:

36

answers:

1

I have a UITableView. On my navbar I have an edit button. I want to be able to enable and disable it depending on certain conditions. For instance, when the user deletes the last of a certain type of row I want to gray out the Edit button as there are no more of these rows to delete.

What I do at the moment is check in

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

to see if I want to disable the edit button (as this seems the most sensible place to do it since the user can only delete these rows with the red delete icon). I then call:

[self.tableView setEditing:NO animated:NO];
[self.navigationItem.leftBarButtonItem setEnabled:NO];

to gray-out the edit button. It works but the title of the edit button is still 'Done' and not 'edit'. Also, if the user adds some rows back and I check to see if I should enable the edit button again - I find that the editing mode is still YES (i.e. the edit button is blue coloured when re-enabled).

How should I approach this?

A: 

Are you using a navigationcontroller? If so, try setting the editing on the controller:

[self.navigationController setEditing:NO animated:NO];
Rengers
Thanks. Works like a charm.
Garry