我试图让我的应用程序根据它正在运行的设备加载不同的故事板。现在,我已经能够检测到设备并基于它设置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-----------------------")
}
为什么你有独立的故事板?这违背了你应该做的一切?并没有规模。 – rmaddy
我会推荐阅读约束...你可能会发现这有帮助:http://stackoverflow.com/documentation/ios/792/auto-layout#t=201608191742048675405 – Azer