I have a st开发者_如何学Pythonandard UINavigationController setup. One particular view displays an "Edit" button on the right side of the Navigation Bar. When that button is pressed and the view switches to editing mode I would like to replace the "Back" button on the left side with an "Add" button. Of course, when editing is finished (the user presses "Done") the button on the left side should change again to the back button.
The obvious answer works. Assuming you have declared a UIBarButtonItem called addButton, you can implement setEditing:animated: as follows:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if(editing) {
self.navigationItem.leftBarButtonItem = addButton;
} else {
self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;
}
}
精彩评论