无法关闭导航控制器中嵌入的View Controller

时间:2019-01-06 16:15:19

标签: swift uinavigationcontroller

我有以下情况。嵌入在导航控制器中的视图控制器。

此视图控制器具有一个按钮,该按钮实例化标签栏控制器,然后显示其一个视图控制器。

当我关闭由标签栏控制器提供的控制器时,我总是在相同的实例中最终出现在初始视图控制器中。

我尝试过的是:

    func showHomeScreen()  {
    //trying to dismiss the current view controller ( will move this code out of this method once i figure out how to do it
    self.navigationController?.popViewController(animated: true)
    self.dismiss(animated: true, completion: nil)
    //showing the next view controller
    let tabBarController = storyboard?.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController

    tabBarController.selectedViewController = tabBarController.viewControllers?[1]
    present(tabBarController, animated: true, completion: nil)
}

self.navigationController?.popViewController => returns nil    self.dismiss(animated: true, completion: nil)似乎什么都没做。

任何人都可以告诉我如何解决此问题,我认为它非常简单,但是我找不到答案。

编辑:这是我的故事板的外观:

https://pasteboard.co/HVdHp6P.png

https://pasteboard.co/HVdHHoG.png

2 个答案:

答案 0 :(得分:0)

发送到下一个viewController后,尝试使用:

navigationController?.viewControllers.remove(at: 1)

这应删除堆栈中第二个的viewController。

答案 1 :(得分:0)

如果导航控制器已推送视图控制器,则效果很好:

self.navigationController?.popToRootViewController(animated: true)
相关问题