检查 UIViewController 是否即将从导航堆栈中弹出? [英] Checking if a UIViewController is about to get Popped from a navigation stack?
问题描述
我需要知道我的视图控制器何时将从导航堆栈中弹出,以便我可以执行操作.
I need to know when my view controller is about to get popped from a nav stack so I can perform an action.
我不能使用 -viewWillDisappear,因为当视图控制器因任何原因移出屏幕时会被调用(比如一个新的视图控制器被推到顶部).
I can't use -viewWillDisappear, because that gets called when the view controller is moved off screen for ANY reason (like a new view controller being pushed on top).
我特别需要知道控制器什么时候会自己弹出.
I specifically need to know when the controller is about to be popped itself.
任何想法都会很棒,提前致谢.
Any ideas would be awesome, thanks in advance.
推荐答案
我不认为对此有明确的消息,但是您可以将 UINavigationController 子类化并覆盖 - popViewControllerAnimated(尽管我自己之前没有尝试过)).
I don't think there is an explicit message for this, but you could subclass the UINavigationController and override - popViewControllerAnimated (although I haven't tried this before myself).
或者,如果没有其他对视图控制器的引用,您可以添加到它的 - dealloc 中吗?
Alternatively, if there are no other references to the view controller, could you add to its - dealloc?
这篇关于检查 UIViewController 是否即将从导航堆栈中弹出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!