簡體   English   中英

與選項卡欄控制器一起使用多個情節提要

[英]Using Multiple Storyboards with Tab Bar Controller

我試圖讓我的應用程序根據運行的設備加載不同的故事板。 現在,我已經能夠檢測到該設備並基於該設備在AppDelegate中設置rootViewController。 但是,我注意到當我這樣做時,我的“標簽欄控制器”消失了。 我認為這是因為我只是將rootViewController設置為新實例而已。 如何解決此問題,以便顯示標簽欄?

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-----------------------")

    } 

只是一個愚蠢的主意:在實例化相關的StoryBoard之前,要使窗口可見。 嘗試在條件語句之后移動makeKeyAndVisible()行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM