如何根据 iOS 版本加载多个故事板文件?(5和6)

时间:2023-03-24
本文介绍了如何根据 iOS 版本加载多个故事板文件?(5和6)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个标签栏控制器应用程序,我正在尝试使其与 iOS 6 和 iOS 5 兼容.对于 iOS 6,我使用自动布局.但是当尝试在 iOS 5 上运行时,由于它无法识别 NSLayoutConstraints 而出现错误.

I have a tab bar controller app that I am trying to make compatible for iOS 6 and iOS 5. For iOS 6, I use auto layout. But when trying to run on iOS 5, I get an error due to it not recognizing NSLayoutConstraints.

据我所知,我需要在未启用自动布局的情况下使用不同的故事板.我已将我的故事板复制到一个新的,但不知道如何设置在应用委托中使用哪个故事板.

From what I can tell, I am required to use a different storyboard without auto layout enabled. I have copied my storyboard into a new one, but don't know how to set which storyboard to use in the app delegate.

执行此操作的代码是什么?

Whats the code to do this?

推荐答案

在您的应用程序委托中,您应该找到如下代码:

In your app delegate, you should find code like this:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];

您可以在此处添加一些代码以在您拥有的几个故事板中进行选择取决于 iOS 的版本:

This is where you can add some code to choose among the several storyboards that you have depending on the version of iOS:

UIStoryboard *storyboard;
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if (...) {
    storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard-v5" bundle:nil];
} else {
    storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard-v6" bundle:nil];
}
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];

这篇关于如何根据 iOS 版本加载多个故事板文件?(5和6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:iOS 中的访问设置应用程序 下一篇:如何在IOS中取消/退出/停止线程对象或后台运行的线程的执行

相关文章