【发布时间】:2016-08-19 16:53:12
【问题描述】:
我正在尝试让我的应用程序根据运行的设备加载不同的故事板。现在,我已经能够检测到设备并基于它在 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-----------------------")
}
【问题讨论】:
-
为什么有单独的故事板?这违背了你应该做的一切?而且它无法扩展。
-
我建议您阅读约束...您可能会发现这很有帮助:stackoverflow.com/documentation/ios/792/…
标签: ios swift uistoryboard