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?

Szu
  • 2,254
  • 1
  • 21
  • 37
JimmyJammed
  • 9,598
  • 19
  • 79
  • 146
  • 1
    Is it worth? Maintaining 2 different storyboards can be a pain. Can't you just drop iOS 5 or auto layout? – Marcelo Mar 31 '13 at 00:29
  • Well disabling auto layout kept causing issues with views being misaligned. But ended up doing it this way for both versions since I would have to deal with it using a 2nd storyboard anyways. – JimmyJammed Mar 31 '13 at 05:14

1 Answers1

10

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];
Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • 2
    Works. But ended up using one storyboard and disabling auto layout and dealing with all the re-setting of struts and springs. Answer is correct for the question though. Thanks! – JimmyJammed Mar 31 '13 at 05:14