【问题标题】:Redirect User to Specific ViewController - Swift 4将用户重定向到特定的 ViewController - Swift 4
【发布时间】:2023-07-10 16:48:01
【问题描述】:

我正在尝试在删除地点后将用户重定向到正确的页面。

navigationController?.popToRootViewController(animated: true)

如果我想重定向到根目录,这将起作用。

navigationController?.popViewController(animated: true)

如果我想重定向到上一个,这将起作用

但就我而言,我想重定向到一个特定页面,而不是根页面或上一个页面。

如何在 iOS 中做这样的事情?

【问题讨论】:

标签: ios swift uinavigationcontroller uinavigationbar segue


【解决方案1】:

如果你现在在你的堆栈中的位置你也可以使用

self.navigationController?.popToViewController(self.navigationController!.viewControllers[1], animated: true)

【讨论】:

  • @kyo 你也不必过滤或循环通过你的 viewControllers ;)
【解决方案2】:

你可以试试

for vc in self.navigationController!.viewControllers {
   if let myVC = vc as? VCName {
     self.navigationController?.popToViewController(myVC, animated: true)
   }
}

【讨论】:

    最近更新 更多