我在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管理导航。
答案 0 :(得分:2)
因为要制作新的导航控制器,然后将标签栏添加为其根视图。
您可以执行以下操作而不是制作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()