【问题标题】:Tab Bar and Navigation Bar won’t show when the ViewController is moved移动 ViewController 时,Tab Bar 和 Navigation Bar 不会显示
【发布时间】:2017-11-28 02:52:41
【问题描述】:

我在 Storyboard 中有一个 ViewController(没有标签栏和导航栏),我需要移动到另一个 ViewController(有标签栏和导航栏)。问题是我可以移动到 ViewController 但它不会显示标签栏和导航栏。

我是这样做的:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let feedTableViewController = storyboard.instantiateViewController(withIdentifier: "Feed") as! FeedTableViewController
self.navigationController?.pushViewController(feedTableViewController, animated: true)

我尝试将 Navigation Bar 和 Tab Bar 嵌入到第一个 ViewController 但我没有运气。这样做的正确方法是什么?

【问题讨论】:

  • 将导航控制器添加到第一个视图控制器。
  • @KKRocks 我试过了,就像我在问题中提到的那样。

标签: ios iphone swift uiviewcontroller storyboard


【解决方案1】:

我找到了解决办法。

而不是启动我想要显示的 ViewController。我启动了 TabBarController 然后显示它,比如:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarViewController = storyboard.instantiateViewController(withIdentifier: "TabBarIdentifier")
self.show(tabBarViewController, sender: nil)

另外,如果 NavigationController 尚未初始化,我们可以这样做:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarViewController = storyboard.instantiateViewController(withIdentifier: "TabBarIdentifier")
let targetNavigationController = UINavigationController(rootViewController: tabBarViewController)
self.show(targetNavigationController, sender: nil)

不过,后一部分与 Storyboard 中已经嵌入的 NavigationController 重叠。如果您有任何要添加的内容,请随时发表评论。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 2022-11-20
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    相关资源
    最近更新 更多