What happens when the back button is pressed in the navigationBar

I wonder what function is called up when the back button is pressed on the navigation bar.

I want to add some functions at the click of a button, who knows?

Thanks in advance

+2
source share
3 answers

The functionality you want is in the protocol UINavigationBarDelegate. Implement the method -navigationBar:shouldPopItem:and set your class as delegatethe navigation bar in question.

+1
source

, , , , . , , "" . , .

0

, "", UINavigationBar, .

The default action for the back button is to pop the current view manager from the navigation stack and return to the previous view manager. If you want to define custom behavior in the lining, you will need to create a new button and bind the action to it:

//Create a new barbutton with an action 
UIBarButtonItem *barbutton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleDone target:self action:@selector(doSomething)];

// and put the button in the nav bar
self.navigationItem.leftBarButtonItem = barbutton;

[barbutton release];

Edit:
// An example of how to implement the doSomething method.

-(void) doSomething
{
//Do your custom behaviour here..

//Go back to the previous viewcontroller
[self.navigationController popViewControllerAnimated:YES];
}
0
source

Source: https://habr.com/ru/post/1790863/


All Articles