有没有人让Swift在iOS 7上玩得很好才能处理多个故事板?
至少,有没有人得到设备后缀才能正常工作?每当我将Master-Detail示例项目中的Main.storyboard重命名为Main~iPad和/或Main~iPhone时,我似乎都会遇到加载错误。
我认为这与设备后缀有关,因为以下内容会做我想要的事情:
var window: UIWindow?
var storyboard: UIStoryboard?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
//device suffixes ~iPad and ~iPhone don't work right now, in fact, a lot of .storyboard stuff is borked
self.window = UIWindow() //window doesn't have an init with frame class, so we need to set that to the screen bounds in order to have touch
self.window!.frame = UIScreen.mainScreen().bounds
//Since I'm targeting iOS 7 and later, we can't use UISplitViewController everywhere (it becomes universal in iOS 8)
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
self.storyboard = UIStoryboard(name: "Main~iPad", bundle: nil)
self.window!.rootViewController = self.storyboard!.instantiateInitialViewController() as UIViewController
//iPad-specific initialization
let splitViewController = self.window!.rootViewController as UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.endIndex-1] as UINavigationController
splitViewController.delegate = navigationController.topViewController as DetailViewController
}else{ //iPhone / iPod
self.storyboard = UIStoryboard(name: "Main~iPhone", bundle: nil)
self.window!.rootViewController = self.storyboard!.instantiateInitialViewController() as UINavigationController
//iPhones should just have a navigation controller as their root view
}
self.window!.makeKeyAndVisible() //got to manually key since we're initializing our window by hand
//at this point we have the iPad storyboard or the iPhone storyboard loaded
return true
}
我知道我们似乎正在逐渐远离特定于设备的标签,但对于那些需要继续支持iOS 7的人来说,回答这一点非常重要。
答案 0 :(得分:1)
设备特定的东西和方向很快就会改变。 iOS 7和Mavericks的Swift源兼容性不保证,但二进制兼容性。也许你遇到了兼容性的限制。