1

Is there a way to connect code to a view's 'back' button that is part of a navigation controller? That back button is automatically coded in by the nature of it being a navigation controller so I am not sure how I can connect code to it.

(I know this should be really easy but I can't seem to find it in the documentation on navigation controller.)

startuprob
  • 1,917
  • 5
  • 30
  • 45

3 Answers3

1

viewWillDisappear is where you would typically add code to execute when the back button is pressed

DVG
  • 17,392
  • 7
  • 61
  • 88
0

You could check if the controller was popped in viewWillDisapper, like in this example:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
        // back button was pressed.  We know this is true because self is no longer
        // in the navigation stack.
        NSLog(@"Article done");
    }
}
Matjan
  • 3,591
  • 1
  • 33
  • 31
0

In reality you should not have a code that needs to be executed when Back button is pressed. What exactly you're trying to achieve?

sha
  • 17,824
  • 5
  • 63
  • 98