2

I wonder what is the function is called when the back button is pressed on the navigationBar.

I want to add some functionality when the button is pressed, who knows it?

Thanks in advance

Ikke
  • 99,403
  • 23
  • 97
  • 120
  • Nicely explained here - http://stackoverflow.com/questions/920379/uinavigationcontroller-intercepting-popviewcontrolleranimated – Dev Dec 03 '12 at 07:23

3 Answers3

1

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

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
  • 5
    This will only work if the navigation bar is not part of a navigation controller. (If it is, you get "*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot manually set the delegate on a UINavigationBar managed by a controller.'") – JosephH Aug 26 '10 at 16:44
0

Assuming you're referring to native controls, there's no way to do quite what you want, just using the built-in stuff. What you want to do is create a 'fake' back button, and stick it up in the left side of the navigation bar. Then you can set its target and action to whatever you like.

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
0

I suppose you're talking about the back button that automatically is added to a UINavigationBar when you push a new viewcontroller on a navigationcontroller.

The default action for the back button is to pop the current viewcontroller from the navigation stack and return to the previous viewcontroller. If you want to define a custom behaviour to the backbutton you'll have to create a new button and tie a selector to it's action property:

//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 on how the doSomething method could be implemented.

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

//Go back to the previous viewcontroller
[self.navigationController popViewControllerAnimated:YES];
}
Mez
  • 2,817
  • 4
  • 27
  • 29