iphone - iOS 7.0 Swift 项目中的多个(特定于设备的) Storyboard

标签 iphone ipad ios7 swift

有人让 Swift 在 iOS 7 上运行得足够好来处理多个 Storyboard吗?

至少,有人获得了可以正常工作的设备后缀吗?每当我将 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 的人们来说非常重要。

最佳答案

设备特定的内容和方向很快就会发生变化。无法保证 iOS 7 和 Mavericks 的 Swift 源代码兼容性,但可以保证二进制兼容性。也许您遇到了兼容性的限制。

关于iphone - iOS 7.0 Swift 项目中的多个(特定于设备的) Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24034521/

相关文章:

iphone - NSPredicate 过滤器

objective-c - 阻止 UIPopover 自动关闭

ipad - 什么导致错误 NSNetServicesErrorCode = "-72000"?

iphone - 推送动画期间的 iOS 7 状态栏颜色。

ios - 防止一个 View Controller ios 7 自动旋转?

ios - 我没有 iPhone5,想在同一版本上测试功能以进行构建,我该怎么做?

ios - respondsToSelector 到 id 类型对象

ios - 如何在后退按钮上重新加载以前的 View Controller ?

objective-c - 得到一个 NSException 不知道为什么

ios - 将圆角半径添加到 UITableViewCell 中的 ImageView 时出现问题