简体   繁体   English

与选项卡栏控制器一起使用多个情节提要

[英]Using Multiple Storyboards with Tab Bar Controller

I'm trying to get my application to load up a different storyboard depending on the device that it is running on. 我试图让我的应用程序根据运行的设备加载不同的故事板。 Right now, I have been able to detect the device and set the rootViewController in the AppDelegate based on it. 现在,我已经能够检测到该设备并基于该设备在AppDelegate中设置rootViewController。 I've noticed, however, that when I do this, my Tab Bar Controller disappears. 但是,我注意到当我这样做时,我的“标签栏控制器”消失了。 I think this is happening because I am simply setting the rootViewController as a new instance. 我认为这是因为我只是将rootViewController设置为新实例而已。 How would I fix this problem so that the Tab Bar will be visible? 如何解决此问题,以便显示标签栏?

AppDelegate.swift 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-----------------------")

    } 

Just a real stupid idea: You are making the window visible before you instantiate the relevant StoryBoard. 只是一个愚蠢的主意:在实例化相关的StoryBoard之前,要使窗口可见。 Try moving the makeKeyAndVisible() line after the conditionals. 尝试在条件语句之后移动makeKeyAndVisible()行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM