gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 07:33:10 27 4
gpt4 key购买 nike

我有以下场景。嵌入在导航 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com