This question already has an answer here:<ul><li> <a href="/questions/54207143/detect-when-view-controller-appears-from-pop" dir="ltr" rel="nofollow">Detect when view controller appears from pop</a> <span class="question-originals-answer-count"> 1 answer </span> </li> </ul>
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 <em>destination</em> view controller. Or to put it another way, detect when a view controller is about to be displayed as a result of a
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.Answer1:
Checkout this property of UIViewController :P
<a href="https://developer.apple.com/documentation/uikit/uiviewcontroller/2097561-ismovingtoparentviewcontroller" rel="nofollow">isMovingToParentViewController</a>
<a href="https://developer.apple.com/documentation/uikit/uiviewcontroller/2097565-ismovingfromparentviewcontroller" rel="nofollow">isMovingFromParentViewController</a>