简体   繁体   English

iOS 8故事板/主界面

[英]iOS 8 Storyboard / Main Interface

I'm creating an iOS 8 app. 我正在创建一个iOS 8应用。 I have two storyboards for iPhone and iPad. 我有两个适用于iPhone和iPad的情节提要。 The iPad.storyboard is set to be the main interface. iPad.storyboard设置为主界面。 My problem is that every time I run on iPhone device, the iPad.storyboard is still being called. 我的问题是,每次我在iPhone设备上运行时,iPad.storyboard仍在被调用。

Is there a way to automatically detect the storyboard for a certain device? 有没有一种方法可以自动检测特定设备的情节提要?

//If you are looking for a swift solution
   if(UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
       //iPad
      var iPadBoard: UIStoryboard!
      iPadBoard = UIStoryboard(name: "iPad", bundle: nil)
      let viewcontroller : UIViewController = iPadBoard.instantiateViewControllerWithIdentifier("iPad") as UIViewController
      self.window!.rootViewController = viewcontroller
    }
    else {
       //iPhone
      var iPhoneBoard: UIStoryboard!
      iPhoneBoard = UIStoryboard(name: "iPhone", bundle: nil)
      let viewcontroller : UIViewController = iPhoneBoard.instantiateViewControllerWithIdentifier("iPhone5") as UIViewController
      self.window!.rootViewController = viewcontroller
    }

To get the iOS to automatically choose for you, name the storyboards with ~iphone and ~ipad at the end (after the name and before the extension.) 要使iOS自动为您选择,请在情节提要的末尾用〜iphone和〜ipad命名(在名称之后和扩展名之前)。

For example: 例如:
main~iphone.storyboard main~ipad.storyboard 主〜iphone.storyboard主〜ipad.storyboard

Note that "iphone" and "ipad" must be lower case. 请注意,“ iphone”和“ ipad”必须为小写。 If you name them with mixed case, they will work on the simulator but not the device because the Mac's default formatting is case-insensitive, but the iOS format is case-sensitive. 如果使用大小写混合的方式命名它们,则它们将在模拟器上运行,但不能在设备上运行,因为Mac的默认格式不区分大小写,而iOS格式区分大小写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM