swift - 无法关闭嵌入在导航 Controller 中的 View Controller

标签 swift uinavigationcontroller

我有以下场景。嵌入在导航 Controller 中的 View Controller 。

这个 View Controller 有一个按钮,可以实例化一个标签栏 Controller ,然后显示它的一个 View Controller 。

当我关闭由选项卡栏 Controller 呈现的 Controller 时,我总是在初始 View Controller 中结束,在它的同一个实例中。

我尝试的是:

    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 => 返回 nil self.dismiss(animated: true, completion: nil) 似乎什么都没做。

谁能告诉我如何解决这个问题,我想它非常简单,但我找不到答案。

编辑:这是我的 Storyboard的样子:

https://pasteboard.co/HVdHp6P.png

https://pasteboard.co/HVdHHoG.png

最佳答案

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

navigationController?.viewControllers.remove(at: 1)

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

关于swift - 无法关闭嵌入在导航 Controller 中的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54063449/

相关文章:

ios - 在 Swift 中打开代码覆盖时出现段错误 11

ios - 如何在 UITabBarController 中插入 UINavigationController

iphone - editButtonItem 标题在完成时重置为默认值

ios - 如果我从推送通知启动我的应用程序,为什么我的导航栏会消失?

ios - UINavigationController navBar 内的 UIPageViewController 中的 UITableViewController 不反弹

ios - 将 UITableViewController 推送到导航堆栈时看不到导航栏

ios - 我不能在 switch 内沮丧吗? ( swift 3)

ios - 迭代字典数组的数组

swift - 有没有办法在 Swift iOS8 中获取特定 GPS 坐标的时区

ios - Swift - bool 的值被改变而不做任何事情?找不到修改的地方吗?