Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the state of an editButtonItem programmatically?

I have a table view which I want to bring up in edit mode under some conditions.

I can set the table itself into editing mode with the following code:

[self.tableView setEditing:YES animated:YES];

But this view controller also has an editButtonItem, which comes up in normal mode, showing "Edit" on the button. I would like to set this button into Edit mode, so it shows "Done" and will toggle the entire table back to normal mode when selected. This button is set up with the typical:

self.navigationItem.rightBarButtonItem = self.editButtonItem;

Is there a way to toggle this button into edit mode programmatically? If I change the style of the button, it changes the appearance, but doesn't actually change the mode of the button.

like image 717
Don Wilson Avatar asked Nov 11 '10 05:11

Don Wilson


1 Answers

With a little more research I answered my own question. I need to set both the table view and the view controller itself to editing mode - then the table, and the editButtonItem will both reflect the correct state. Like this:

[self.tableView setEditing:YES animated:YES];
[self setEditing:YES];
like image 89
Don Wilson Avatar answered Oct 21 '22 13:10

Don Wilson