开发者

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 thi开发者_JS百科s 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.


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜