这是流程:VC1
->(推(->VC2
->(推(->VC3
当点击VC3
中的一个按钮时,我正在调用下面的方法,它工作正常-将我带回VC1
:
self.navigationController?.popToRootViewController(animated: false)
但问题出现在VC1
中的viewWillAppear()
方法中,该方法未被调用
有什么解决方案吗?
我不太确定,但加载控制器时会调用viewWillAppear()
。它在关闭其他控制器时不会调用。因此,您需要尝试custom Delegate
或Notification observer
。
你可以在这里完成技巧:
if let root = navigationController?.viewControllers.last(where: { $0 is YourRootController }) {
navigationController?.popToViewController(root, animated: true)
}