2016-08-19 67 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

那似乎没有工作。标签栏仍然不可见。 –

相关问题