gpt4 book ai didi

ios - popToRootViewController 然后 pushViewController

转载 作者:行者123 更新时间:2023-11-28 14:02:25 25 4
gpt4 key购买 nike

我正在尝试编写一段代码,它将弹出到 Root View Controller ,然后将推送另一个 View Controller ,到目前为止我有这个:

self.navigationController?.popToRootViewController(animated: true)

let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Posts") as! PostsController

self.navigationController?.pushViewController(viewController, animated: true)

导航 Controller 将转到 Root View Controller ,但它不会推送另一个 View Controller ,我得到这是我的控制台日志:

Presenting view controllers on detached view controllers is discouraged

我想做的事情是不可能的吗?

最佳答案

试试这个-

if let navCont = navigationController {
var controllers = navCont.viewControllers
controllers.removeLast()
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Posts") as! PostsController
controllers.append(viewController)
navCont.setViewControllers(controllers, animated: true)
}

关于ios - popToRootViewController 然后 pushViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53437242/

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