TabBar 和 NavigationBar 的问题
Issues with the TabBar and NavigationBar
我在 TabBar 中有两个视图控制器。我设置为如果用户已登录,则它直接显示 TabBar,否则它显示登录 ViewController。查看 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但是当用户已经登录时它在首页显示导航栏ViewController。
这是我的故事板设置。
以及如何使用 TabBar 管理导航。
因为你正在制作新的导航控制器然后添加标签栏作为它的根视图。
你可以这样做而不是制作 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()
我在 TabBar 中有两个视图控制器。我设置为如果用户已登录,则它直接显示 TabBar,否则它显示登录 ViewController。查看 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但是当用户已经登录时它在首页显示导航栏ViewController。
这是我的故事板设置。
以及如何使用 TabBar 管理导航。
因为你正在制作新的导航控制器然后添加标签栏作为它的根视图。
你可以这样做而不是制作 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()