2016-08-19 65 views
0

我試圖讓我的應用程序根據它正在運行的設備加載不同的故事板。現在,我已經能夠檢測到設備並基於它設置AppDelegate中的rootViewController。不過,我注意到,當我這樣做時,我的Tab Bar Controller消失了。我認爲這是因爲我簡單地將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-----------------------") 

    } 
+1

爲什麼你有獨立的故事板?這違背了你應該做的一切?並沒有規模。 – rmaddy

+0

我會推薦閱讀約束...你可能會發現這有幫助:http://stackoverflow.com/documentation/ios/792/auto-layout#t=201608191742048675405 – Azer

回答

1

只是一個真正愚蠢的想法:你是使該窗口可見實例化相關的故事板前。嘗試在條件之後移動makeKeyAndVisible()行。

+0

好的,謝謝你,我會嘗試 –

+0

那似乎沒有工作。標籤欄仍然不可見。 –

相關問題