繁体   English   中英

在不同的导航中从一个视图 Controller 弹出到另一个视图 controller

[英]Pop from one View Controller to another in a different navigation controller

I am trying to pop a view controller VC1 from one navigation controller NC1 to another view controller VC2 in another navigation controller NC2.

我正在使用 VIPER 架构,因此在不同导航层次结构中的不同视图控制器之间进行路由要求我必须切换到我想要呈现的导航 controller 的根目录。

So the issue here is that, after navigating to the view controller VC2 of the second navigation controller NC2, I want to go back to the first view controller VC1 in the first navigation controller NC1.

我尝试了以下方法:

 self.navigationController?.popViewController(animated: true)

 navigationController?.dismiss(animated: true, completion: nil)

 view.window?.rootViewController?.dismiss(animated: true, completion: nil)

 self.navigationController?.popToRootViewController(animated: true)

但没有一个对我有用。 有任何想法吗?

请尝试以下代码:

let viewControllers = self.navigationController?.viewControllers

for vc in viewControllers! {

   if vc is VC1 {
      self.navigationController?.popToViewController(vc as! VC1, animated: true)
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM