swift – 在App Delegate中管理两个故事板

swift – 在App Delegate中管理两个故事板,第1张

概述我决定避免使用自动布局,所以我正在尝试实现代码,以使我的应用程序根据屏幕大小管理两个不同的故事板. 我一直在关注本教程:http://pinkstone.co.uk/how-to-load-a-different-storyboard-depending-on-screen-size-in-ios/ 我在尝试将Objective C代码转换为Swift时遇到问题. 这是我目前在AppDelegat 我决定避免使用自动布局,所以我正在尝试实现代码,以使我的应用程序根据屏幕大小管理两个不同的故事板.

我一直在关注本教程:http://pinkstone.co.uk/how-to-load-a-different-storyboard-depending-on-screen-size-in-ios/

我在尝试将Objective C代码转换为Swift时遇到问题.

这是我目前在AppDelegate中的代码:

@UIApplicationMainclass AppDelegate: UIResponder,UIApplicationDelegate {var window: UIWindow?func grabStoryboard() -> UIStoryboard {    var storyboard = UIStoryboard()    var height = UIScreen.mainScreen().bounds.size.height    if height == 480 {        storyboard = UIStoryboard(name: "Main3.5",bundle: nil)    } else {        storyboard = UIStoryboard(name: "Main",bundle: nil)    }    return storyboard}func application(application: UIApplication!,dIDFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {    // OverrIDe point for customization after application launch.       var storyboard: UIStoryboard = self.grabStoryboard()    self.window?.rootVIEwController.storyboard.instantiateInitialVIEwController()    self.window?.makeKeyAndVisible()    return true}

该应用程序运行,我没有错误,但无论我是在3.5英寸设备或4英寸设备上运行应用程序,我只是得到4英寸的故事板.

我哪里错了?

解决方法 问题在于:

self.window?.rootVIEwController.storyboard.instantiateInitialVIEwController()

您应该使用此代替:

self.window?.rootVIEwController = storyboard.instantiateInitialVIEwController()

编辑:我已删除UIVIEwController,因为它不再需要.

总结

以上是内存溢出为你收集整理的swift – 在App Delegate中管理两个故事板全部内容,希望文章能够帮你解决swift – 在App Delegate中管理两个故事板所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/999727.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存