使用带有标签栏控制器的多个故事板

时间:2016-08-19 16:53:12

标签: ios swift uistoryboard

我正在尝试让我的应用程序加载不同的故事板,具体取决于它运行的设备。现在,我已经能够检测到设备并根据它在AppDelegate中设置rootViewController。但是,我注意到,当我这样做时,我的标签栏控制器消失了。我认为这种情况正在发生,因为我只是将rootViewController设置为一个新实例。我该如何解决这个问题,以便Tab Bar可见?

AppDelegate.swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    window =  UIWindow(frame: UIScreen.mainScreen().bounds)
    window?.makeKeyAndVisible()


    if ((UIDevice.currentDevice().modelName == "iPhone 5") || (UIDevice.currentDevice().modelName == "iPhone 5c") || (UIDevice.currentDevice().modelName == "iPhone 5s") || (UIDevice.currentDevice().modelName == "iPhone SE") || (UIDevice.currentDevice().modelName == "iPod Touch 5") || (UIDevice.currentDevice().modelName == "iPod Touch 6")) {

        storyboard = UIStoryboard(name: "iPhoneSE", bundle: nil)
        let rootController = storyboard!.instantiateViewControllerWithIdentifier("login5")

        if let window = self.window {
            window.rootViewController = rootController
        }

        print("-----------------------iPhone5-----------------------")

    } else if ((UIDevice.currentDevice().modelName == "iPhone 6") || (UIDevice.currentDevice().modelName == "iPhone 6s")){

        storyboard = UIStoryboard(name: "iPhone6", bundle: nil)
        let rootController = storyboard!.instantiateViewControllerWithIdentifier("login6")

        if let window = self.window {
            window.rootViewController = rootController
        }

        print("-----------------------iPhone6-----------------------")

    } 

1 个答案:

答案 0 :(得分:1)

只是一个真正愚蠢的想法:在实例化相关的StoryBoard之前,您正在使窗口可见。尝试在条件之后移动makeKeyAndVisible()行。