【发布时间】: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