gpt4 book ai didi

swift - TabBar 和 NavigationBar 的问题

转载 作者:搜寻专家 更新时间:2023-11-01 06:53:49 27 4
gpt4 key购买 nike

我在 TabBar 中有两个 View Controller 。我设置为如果用户已登录,则它直接显示 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 中显示导航栏。

enter image description here

这是我的 Storyboard设置。 enter image description here

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

最佳答案

因为你正在制作新的导航 Controller 然后添加标签栏作为它的 Root View 。

您可以这样做,而不是制作 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()

关于swift - TabBar 和 NavigationBar 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55204439/

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