我一直在关注本教程: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中管理两个故事板所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)