开发者

Disabling back button and put Cancel button in navigation view controller -- like contacts iPhone application

开发者 https://www.devze.com 2023-02-28 06:52 出处:网络
I have a navigation view controller and there are 3 view controllers in the navigation stack. Now on the third and top most visible view controller I have 开发者_运维问答a default back button coming i

I have a navigation view controller and there are 3 view controllers in the navigation stack. Now on the third and top most visible view controller I have 开发者_运维问答a default back button coming in.

I need to bring this view controller in edit mode which I did... Now the requirement is to have a cancel button as the left bar button item instead of back button.

This is similar to the functionality given by contacts application of iPhone where you edit a particular contact.

Any clue how to achieve this?


To hide back button and add a left bar button use-

[self.navigationItem setHidesBackButton:TRUE];

    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector()];
    [self.navigationItem setLeftBarButtonItem:leftBarButton];
    [leftBarButton release];

And then to programmatically return to the previous view controller, you can do-

[self.navigationController popViewControllerAnimated:YES];


This is a simpler way:

[self.navigationItem setHidesBackButton:YES];


If you are using storyboard, you can also just drag a bar button item onto the navbar where the back button would normally show up. This will override it.

0

精彩评论

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

关注公众号