Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

ios5 - How to load multiple storyboard files depending on iOS version? (5 and 6)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...