为什么我的 UITabBar 在加载入职屏幕后消失了?
Why does my UITabBar disappear after onboarding screen is loaded?
我使用的是 Tab Bar Controller
,它工作正常,但是当我的应用程序首次启动我的入职屏幕供用户接受条款和条件时,标签栏消失了。
我不太确定在这里做什么。这是我的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//tnc screen ----------------------------------------------
let launchedBefore = UserDefaults.standard.bool(forKey: "hasLaunched")
self.window = UIWindow(frame: UIScreen.main.bounds)
let launchStoryboard = UIStoryboard(name: "Onboarding", bundle: nil)
let mainStoryboard = UIStoryboard (name: "Main", bundle: nil)
var vc: UIViewController
if launchedBefore {
vc = mainStoryboard.instantiateInitialViewController()!
} else {
vc = launchStoryboard.instantiateViewController(withIdentifier: "FirstLaunch")
}
UserDefaults.standard.set(true, forKey: "hasLaunched")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
//end tnc screen ---------------------------------------------
我应该如何解决这个问题?
这是因为您用 T&C 情节提要掩盖了您的 UITabBarController
情节提要。
我倾向于完全放弃故事板,拥有一个根 UITabBarController
,并在 UIViewControllers
所说的 TabBarController
管理之一上,添加一个子视图以接受 T&C。
放弃故事板看起来像这样:
UIWindow
--UITabBarController (the windows root view controller)
----UIViewController for tab 1
------UIView to show T&C
----UIViewController for tab 2
----UIViewController for tab n
我设法通过将此添加到我的同意按钮(在我的 tnc 的故事板上)来修复它:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
self.present(homeVC, animated: true, completion: nil)*/
let controller = storyboard.instantiateViewController(withIdentifier: "TabBarController"); addChild(controller)
view.addSubview(controller.view)
controller.didMove(toParent: self)
非常感谢@Woodstock 和@Teetz 帮助我理解了它背后的逻辑! :)
我使用的是 Tab Bar Controller
,它工作正常,但是当我的应用程序首次启动我的入职屏幕供用户接受条款和条件时,标签栏消失了。
我不太确定在这里做什么。这是我的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//tnc screen ----------------------------------------------
let launchedBefore = UserDefaults.standard.bool(forKey: "hasLaunched")
self.window = UIWindow(frame: UIScreen.main.bounds)
let launchStoryboard = UIStoryboard(name: "Onboarding", bundle: nil)
let mainStoryboard = UIStoryboard (name: "Main", bundle: nil)
var vc: UIViewController
if launchedBefore {
vc = mainStoryboard.instantiateInitialViewController()!
} else {
vc = launchStoryboard.instantiateViewController(withIdentifier: "FirstLaunch")
}
UserDefaults.standard.set(true, forKey: "hasLaunched")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
//end tnc screen ---------------------------------------------
我应该如何解决这个问题?
这是因为您用 T&C 情节提要掩盖了您的 UITabBarController
情节提要。
我倾向于完全放弃故事板,拥有一个根 UITabBarController
,并在 UIViewControllers
所说的 TabBarController
管理之一上,添加一个子视图以接受 T&C。
放弃故事板看起来像这样:
UIWindow
--UITabBarController (the windows root view controller)
----UIViewController for tab 1
------UIView to show T&C
----UIViewController for tab 2
----UIViewController for tab n
我设法通过将此添加到我的同意按钮(在我的 tnc 的故事板上)来修复它:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
self.present(homeVC, animated: true, completion: nil)*/
let controller = storyboard.instantiateViewController(withIdentifier: "TabBarController"); addChild(controller)
view.addSubview(controller.view)
controller.didMove(toParent: self)
非常感谢@Woodstock 和@Teetz 帮助我理解了它背后的逻辑! :)