问题
There are a number of well known solutions for detecting when a view controller is in the process of disappearing off the screen in the process of a backwards navigation, managed by a UINavigationController (i.e. when a view controller is being popped off the navigation stack). In other words detecting a backwards navigation within the source view controller.
In contrast, I need to detect a backwards navigation within viewWillAppear for the destination view controller. Or to put it another way, detect when a view controller is about to be displayed as a result of a UINavigationController pop.
What is the cleanest/simplest way to achieve this? Implementing UINavigationControllerDelegate and setting a flag might be one approach, but would rather avoid mutable state if possible.
I am not using Storyboards to manage the transition between these two screens.
回答1:
Checkout this property of UIViewController :P
isMovingToParentViewController
isMovingFromParentViewController
来源:https://stackoverflow.com/questions/47157766/detect-backward-pop-navigation-in-destination-view-controller-viewwillappear