Code Code - 1 year ago 67
iOS Question

Detecting when the 'back' button is pressed on a navbar

I need to perform some actions when the back button(return to previous screen, return to parent-view) button is pressed on a Navbar.

Is there some method I can implement to catch the event and fire off some actions to pause and save data before the screen disappears?

Answer Source

Just implement your own action for the button:

    [self.navigationItem.backBarButtonItem setAction:@selector(perform:)];

-(void) perform:(id)sender {

     //do your saving and such here

     [self.navigationController popViewControllerAnimated:NO];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download