【问题标题】:Top navigation bar doesn't appear顶部导航栏不出现
【发布时间】:2023-04-04 07:38:01
【问题描述】:

我有一个顶部导航栏,上面有一个注销按钮,可让用户返回登录屏幕并从钥匙串中擦除他们的访问令牌。

我正在添加一个滑出菜单栏,但是,我的顶部导航栏没有出现,我似乎无法让它出现。

我正在使用以下代码摘录来展示关于成功登录的观点:

DispatchQueue.main.async {
    let homePage = 
        self.storyboard?.instantiateViewController(withIdentifier:
        "HomePageViewController") as! HomePageViewController
    self.present(homePage, animated: true)
}

【问题讨论】:

    标签: ios uinavigationbar


    【解决方案1】:

    您必须出示UINavigationControllerHomePageViewController,而不是出示HomePageViewController

    • UINavigationControllerHomePageViewController 设置故事板ID。例如,您将 UINavigationController 的情节提要 ID 设置为 HomePageNavigation
    • 用下面的代码替换你的代码。

      DispatchQueue.main.async {
          let homePage = 
              self.storyboard?.instantiateViewController(withIdentifier:
      "HomePageNavigation") as! UINavigationController
          self.present(homePage, animated: true)
      }
      

    在情节提要上选择 UINavigationControllerHomePageController

    更改 UINavigationController 的情节提要 ID。

    【讨论】:

    • 感谢您的回答,但我有点困惑。我了解更改我的代码,但我对我更改有关情节提要/类 ID 的变量感到困惑。我的主页视图有一个类和情节提要 ID:HomePageViewController。我附加到该主页的导航控制器没有设置任何内容。
    • 抱歉,我又花了几分钟时间查看了您的答案并意识到您想要什么。将控制器的情节提要 ID 设置为 HomePageNavigation 并附加我的代码。有效。我可以看到导航栏
    • @Harrison 太好了,我也更新了我的答案。有需要的可以去看看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多