Swift中的多个故事板

Jos*_*nor 6 iphone ios swift

我有一个有4个故事板的应用程序,每个用于不同的设备(iphone4,5,6,6 +).我曾尝试使用自动约束,但由于我的应用程序很复杂,我无法弄明白.我听说如果你有多个故事板,应该有一种方法来指定在app委托中使用哪个故事板.如何为app委托中的正确设备指定正确的故事板?我目前有四个故事板,命名为:

iphone4s.storyboard
iphone5.storyboard
iphone6.storyboard
iphone6plus.storyboard

谢谢.

Mid*_* MP 1

实现一个在指定名称时检索故事板的函数。

func getStoryBoard(name : String)-> UIStoryboard
{
    var storyBoard = UIStoryboard(name: name, bundle: nil);
    return storyBoard;
}
Run Code Online (Sandbox Code Playgroud)

更改应用程序委托方法,例如:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
    var storyBoard = getStoryBoard("Main") // Change the storyboard name based on the device, you may need to write a condition here for that
    var initialViewController: UIViewController = storyBoard.instantiateInitialViewController() as! UIViewController
    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()
    // Override point for customization after application launch.
    return true
}
Run Code Online (Sandbox Code Playgroud)