为什么加载了载入屏幕后我的UITabBar消失了?

时间:2019-02-12 08:55:14

标签: ios swift uinavigationcontroller uitabbar

我使用的是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 ---------------------------------------------

我该如何解决?

2 个答案:

答案 0 :(得分:0)

这是因为您将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

答案 1 :(得分:0)

我设法通过将其添加到我的同意按钮(与我的tncs一起放在情节提要上)来解决此问题:

    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帮助我了解其背后的逻辑! :)