简体   繁体   中英

iPhone Dev, UINavigationController, How to Programmatically Tell when Back Button is Pressed

I have a UINavigationController, and I was wondering how I can programmatically tell when it has been pressed?

I am asking because I need to perform some actions when the back button is pressed, and ONLY when the back button is pressed. There are cases when I programmatically press the back button, and I need to ignore those instances. Does anyone have a suggestion?

Thanks!


Here is how the problem was solved:

I have a flag set in my application delegate. Initially it is set to False. When I programmatically push the button I set it to TRUE. Then, in the viewWillAppear method of my top view controller, I test the flag and perform necessary actions. I then reset the flag to False.

When you press the button programmatically set a flag. When you go to perform the post press actions check if the flag is set.

There doesn't seem to be a delegate method for that, but there is this one which when used like this could work for what you need.

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

  if ([viewController isKindOfClass:[MasterViewController class]]) { } 

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM