Detect backward/pop navigation in destination view controller viewWillAppear [duplicate]

余生长醉 提交于 2019-12-20 04:39:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!