【发布时间】:2019-02-12 08:55:13
【问题描述】:
我正在使用Tab Bar Controller,它工作正常,但是当我的应用程序第一次从我的入职屏幕启动以供用户接受 T&C 时,标签栏消失了。
我不太确定在这里做什么。这是我的代码:
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 ---------------------------------------------
我应该如何解决这个问题?
【问题讨论】:
-
我的猜测是,您的 mainStoryboard 中的 initialViewController 是您的 UITabBarController - 如果您将另一个 ViewController 设为您的 rootViewController,为什么 TabBarController 会出现呢?我认为您应该尝试从 TabBarController 显示您的“FirstLaunch” ViewController,而不是将其配置为 rootViewController
-
@Teetz :啊,好吧,我想明白你在说什么。如果我错了,请纠正我,但这意味着我应该更改这部分代码:
self.window?.rootViewController = vc? -
就像 Woodstock 展示了 ViewHierarchy。有更多方法可以实现您的需求,但我认为最好不要更改 rootViewController(rootViewController 始终是 TabBarController),您只需将 T&C ViewController 显示为 subView(从 TabBarController 呈现)
标签: ios swift uinavigationcontroller uitabbar