选项卡栏中有两个视图控制器。我设置为如果用户已登录,则直接显示选项卡栏,否则显示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
}}
但是当我通过login-viewcontroller时工作正常,但当用户已经登录时,它会在homeviewcontroller中显示导航栏。
这是我的故事板设置。
以及如何使用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()
关于swift - 标签栏和导航栏的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55204439/