0

我一直在尝试找到解决方案,但没有一个可用的解决方案对我有用,有人可以告诉我如何实现这一目标吗?

成功登录后,我使用以下代码将 rootviewcontroller 设置为视图控制器(Container Viewcontroller)。

 let vc = self.storyboard?.instantiateViewController(withIdentifier: "ContainerViewController") as! ContainerViewController
 let appdelegate = UIApplication.shared.delegate as! AppDelegate
 appdelegate.window!.rootViewController = vc

根据收到的特定通知,我定义了一个自定义函数,该函数肯定会被调用,但我希望我的应用用户自动返回根目录,而不管他当前使用的导航控制器如何。我正在使用此代码

 guard let navigationController = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController else { return }
 navigationController.popToRootViewController(animated: true)

流程是 Root(VC)->NavigationController1->PushingViewController2->PushingViewController3,假设用户当前在 ViewController3(已推送),我想将用户从另一个正在观察网络状态的类 NSOBject 中取回,并且在网络故障时它正在调用ABC 函数,但是当我添加上述导航控制器引用以弹出所有导航控制器时,它不起作用。

4

0 回答 0