开发者

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 p开发者_运维技巧ush 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]]) {
 }

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜