在 popToRootViewController

问题描述

流程如下:
VC1 ->(PUSH)-> VC2 ->(PUSH) -> VC3
单击 VC3 中的按钮时,我正在调用下面的方法并且它正常工作 - 带我回到 VC1

self.navigationController?.popToRootViewController(animated: false)

但问题在于 viewWillAppear() 中的 VC1 方法没有被调用。
有什么办法可以调用吗?

解决方法

我不太确定,但是在加载控制器时会调用 viewWillAppear()。它不会在关闭其他控制器时调用。因此,您需要尝试 custom DelegateNotification observer

,

你可以在这里完成:

if let root = navigationController?.viewControllers.last(where: { $0 is YourRootController }) {
     navigationController?.popToViewController(root,animated: true)
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...