Disabling the back button and the cancel button in the navigation view manager - for example, iPhone contacts

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.

I need to bring this view controller to edit mode, which I did ... Now the requirement is that the cancel button be pressed as the left button, and not the back button.

This is similar to the functionality defined by the iPhone contacts application where you edit a specific contact.

Any hint on how to do this?

+5
source share
3 answers

To hide the back button and add a left button -

[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];
+18
source

If you are using a storyboard, you can also simply drag a panel button element onto the navigation bar, where the return button usually appears. This will override it.

0
source

:

[self.navigationItem setHidesBackButton:YES];
0

All Articles