我试图让我的应用程序根据运行的设备加载不同的 Storyboard。现在,我已经能够检测到设备并基于它在 AppDelegate 中设置 rootViewController。但是,我注意到,当我这样做时,我的选项卡栏 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-----------------------")
}
最佳答案
这只是一个真正愚蠢的想法:在实例化相关 StoryBoard 之前让窗口可见。尝试在条件语句之后移动 makeKeyAndVisible() 行。
关于ios - 将多个 Storyboard与选项卡栏 Controller 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39044203/