iPhone 开发,UINavigationController,如何以编程方式判断何时按下后退按钮
我有一个 UINavigationController,我想知道如何以编程方式判断它何时被按下?
我这么问是因为我需要在按下后退按钮时执行一些操作,并且仅在按下后退按钮时执行一些操作。在某些情况下,当我以编程方式按下后退按钮时,我需要忽略这些实例。有人有建议吗?
谢谢!
以下是问题的解决方法:
我在应用程序委托中设置了一个标志。最初它被设置为 False。当我以编程方式按下按钮时,我将其设置为 TRUE。然后,在顶视图控制器的 viewWillAppear 方法中,我测试该标志并执行必要的操作。然后我将标志重置为 False。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您按下按钮时,以编程方式设置一个标志。当您执行印后操作时,请检查是否设置了该标志。
When you press the button programmatically set a flag. When you go to perform the post press actions check if the flag is set.
似乎没有一个委托方法可以实现这一点,但是有一个这样的方法,当像这样使用时可以满足您的需要。
<代码>
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
动画:(BOOL)动画 {
}
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 {
}