简体   繁体   中英

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. 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. How would I fix this problem so that the Tab Bar will be visible?

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. Try moving the makeKeyAndVisible() line after the conditionals.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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