【问题标题】:Issues with the TabBar and NavigationBarTabBar 和 NavigationBar 的问题
【发布时间】:2019-03-17 06:28:10
【问题描述】:

我在 TabBar 中有两个视图控制器。我设置为如果用户已登录,则直接显示 TabBar,否则显示 loginViewController。查看AppDelegate中的代码

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true])

        let status = UserDefaults.standard.bool(forKey: "status")

        //StoryBoard Decide
        if (status == false){
            let storyBoard : UIStoryboard = UIStoryboard(name: "Tools", bundle:nil)
            let nextViewController = storyBoard.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
            let navigationController = UINavigationController(rootViewController: nextViewController)
            let appdelegate = UIApplication.shared.delegate as! AppDelegate
            appdelegate.window!.rootViewController = navigationController
        }else {
            let storyBoard : UIStoryboard = UIStoryboard(name: "Tools", bundle:nil)
            let nextViewController = storyBoard.instantiateViewController(withIdentifier: "tabbar") as! UITabBarController
            let navigationController = UINavigationController(rootViewController: nextViewController)
            let appdelegate = UIApplication.shared.delegate as! AppDelegate
            appdelegate.window!.rootViewController = navigationController
        }}

但是当我通过登录 ViewController 时它工作正常,但当用户已经登录时,它会在 HomeViewController 中显示导航栏。

这是我的故事板设置。

以及如何使用 TabBar 管理导航。

【问题讨论】:

    标签: swift uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    因为您正在制作新的导航控制器,所以添加标签栏作为其根视图。

    您可以这样做,而不是制作 UINavigationController:

    替换

    let nextViewController = storyBoard.instantiateViewController(withIdentifier: "tabbar") as! UITabBarController
    let navigationController = UINavigationController(rootViewController: nextViewController)
    let appdelegate = UIApplication.shared.delegate as! AppDelegate
    appdelegate.window!.rootViewController = navigationController
    

    与:

    let nextViewController = storyBoard.instantiateViewController(withIdentifier: "tabbar") as! UITabBarController
    self.window?.rootViewController = nextViewController
    self.window?.makeKeyAndVisible()
    

    【讨论】:

    • 哦,太好了,你节省了我的时间。你能解释一下吗
    • 我的 moreViewController 中有表格,使用 Didselect 我推送 ViewController 但它无法正常工作
    • 我在前两行解释了它。我应该更详细地解释什么?你也可以问你第二个问题作为新问题。
    猜你喜欢
    • 2011-07-14
    • 1970-01-01
    • 2014-05-18
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 2013-10-17
    相关资源
    最近更新 更多