首页 > 解决方案 > 从导航控制器回到视图控制器?

问题描述

我是 Swift 开发的初学者,我被困在某一点上。我有一个 ViewController1(入口点)、导航控制器和 ViewController2。ViewController2 包含XLPagerTabStrip并嵌入在导航控制器中。我可以使用以下代码从 ViewController1 移动到导航控制器。

let navigationController = mainStoryBoard.instantiateViewController(withIdentifier: "NavigationController") as! UINavigationController

let viewController = mainStoryBoard.instantiateViewController(withIdentifier: "ParentViewController") as! ParentViewController
navigationController.pushViewController(viewController, animated: true)

self.present(navigationController, animated: true, completion: nil)

现在的问题是我无法从导航控制器移回 ViewController1。

能够从ViewController1 -> NavigationController -> ViewController2移动

但无法后退,即ViewController1 <- NavigationController <- ViewController2

提前致谢。

标签: swiftuinavigationcontroller

解决方案


尝试任何一个

navigationController?.popViewController(animated: true)

dismiss(animated: true, completion: nil)

推荐阅读