开发者

How do I replace the back button with another UIBarButtonItem in a navigation controller when editing?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜