多个故事板不起作用

Multiple storyboards not working

我正在使用此代码根据屏幕加载每个故事板,但唯一有效的是 480,其他所有的都没有工作,只是空白

我该如何解决这个问题 谢谢

 var window: UIWindow?

    func grabStoryboard() -> UIStoryboard {
        var storyboard = UIStoryboard()
        let height = UIScreen.mainScreen().bounds.size.height

        if height == 480 {
            storyboard = UIStoryboard(name: "main3.5", bundle: nil)


        if height == 568 {
                storyboard = UIStoryboard(name: "main4", bundle: nil)
            }


        if height == 667 {
                storyboard = UIStoryboard(name: "main6", bundle: nil)
            }

        if height == 736 {
                storyboard = UIStoryboard(name: "main6plus", bundle: nil)
            }
        } else {
            storyboard = UIStoryboard(name: "Main", bundle: nil)
        }
        return storyboard
    }

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.


        let storyboard: UIStoryboard = self.grabStoryboard()

        self.window?.rootViewController =
            storyboard.instantiateInitialViewController()! as UIViewController
        self.window?.makeKeyAndVisible()
        return true
    }

568、667 和 736 的 if 在 480 语句中,因此永远不会到达它们。希望对您有所帮助。

你的语法有误。您需要像下面这样以正确的方式使用 if-else 语句。您可以查看 Swift 文档 Swift Control Flow。转到 Conditional Statements.

部分
func grabStoryboard() -> UIStoryboard {
    var storyboard = UIStoryboard()
    let height = UIScreen.mainScreen().bounds.size.height

    if height == 480 {
        storyboard = UIStoryboard(name: "main3.5", bundle: nil)
    } else if height == 568 {
        storyboard = UIStoryboard(name: "main4", bundle: nil)
    } else if height == 667 {
        storyboard = UIStoryboard(name: "main6", bundle: nil)
    } else if height == 736 {
        storyboard = UIStoryboard(name: "main6plus", bundle: nil)
    } else {
        storyboard = UIStoryboard(name: "Main", bundle: nil)
    }

    return storyboard
}