多个故事板不起作用



我使用此代码根据屏幕加载每个故事板,但唯一有效的是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
}

相关内容

  • 没有找到相关文章

最新更新