gpt4 book ai didi

swift - 使用 Swift 3 在两个 Storyboard之间移动时导航栏消失

转载 作者:行者123 更新时间:2023-11-28 08:13:41 26 4
gpt4 key购买 nike

我目前从事的项目有多个 Storyboard。我们使用以下代码以编程方式从第一个 Storyboard移动到下一个 Storyboard:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "DiscoverViewController") as UIViewController
self.present(vc, animated: true, completion: nil)

它要移动到的 Storyboard的 Storyboard入口点指向上面正在实例化和呈现的 View Controller 的导航 Controller 。

问题是当页面显示时,导航栏没有出现。它出现在故事​​板 View 上,在我们分离 Storyboard之前,我们没有遇到这个问题。

我从一个 Storyboard转到另一个 Storyboard的方式有问题吗?我是否需要呈现导航 Controller 而不是 View Controller ?

谢谢!

最佳答案

这是因为您正在呈现 View Controller ,而您可能想将其推送到导航堆栈。

This答案显示了您需要做什么。这是为您的示例改编的代码:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "DiscoverViewController") as UIViewController
self.navigationController?.pushViewController(vc, animated: true)

关于swift - 使用 Swift 3 在两个 Storyboard之间移动时导航栏消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43035094/

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