How to load different Storyboards for different versions of iOS in Xcode 5

No matter how hard I’ve tried to tweak my Storyboard, there are always areas that only look well on one particular version of iOS. There is no “one Storyboard fits all” approach.

The easiest option is to have one Storyboard for iOS 6 and another for iOS 7 – then everybody’s happy. Question is, how do we tell our app which one to load depending on the iOS version our device is running?

Here’s how: AppDelegate.m to the rescue! Let’s determine it in applicationDidFinishLaunchingWithOptions:

This will override whichever Storyboard is defined in the target (under Deployment Info, Main Interface).

8 thoughts on “How to load different Storyboards for different versions of iOS in Xcode 5

  1. Wondering if this same code can be edited to allow the user to save the settings (preference) of which storyboard they prefer. I have an app that uses an Imperial Storyboard and a Metric Storyboard. At startup the user actually sees a Startup Storyboard and then they select Imperial or Metric… That works fine…

    I have an option to allow them to save their default unit of measure, so they don’t have to select Imperial or Metric every time they start the app again using NSUserDefaults… Those defaults too save properly.

    My problem is, that I cannot tell in the AppDelegate file that if the user saved Imperial, how to only display the Imperial Storyboard on next entry, and of course, if the user selected Metric, how to load only that Storyboard.

    So while I came close to editing your sample (thank you) I am having a bit of trouble having the AppDelegate file handle the selection.

    If you have any advice much appreciated…

    Here is some sample code… (not working) no errors, just not selecting the saved Storyboard from the user preferences as every time the app starts up, it always goes to the Start Storyboard and not the Imperial or Metric Storyboard…

    ***Code Below *** in AppDelegate.m

    Then in the following…

    ***

    so again, there are no errors, only that the app ALWAYS starts at the Start Storyboard, even though the user as selected the Imperial storyboard to start at the next time they enter the app…

    Any help much appreciated…

    John

    1. Hi John, your logic is sound and it’s definitely possible. Your code is correct too as far as I can see, there’s just one small thing when it comes to checking the user defaults.

      In applicationDidFinishLaunching, you’re saying “if the BOOL isn’t set, then set it”. This overrides the value every time the app starts, even if the user has chosen metric. What you want to do instead, “if the BOOL is set, load the imperial storyboard. And if the BOOL is not set, then load the metric storyboard”.

      In code this could look something like this:

      Here’s a quick demo project: https://github.com/versluis/Pick-a-Storyboard/

      Hope this helps!

      1. So using your method, I edited to show the Start Controller to allow the user to show the options, if they do not set them, at all… just a simple else if added… code below for reference…

        Then added the extra storyboard like this…

        Again, thanks for all your help!

    2. If anyone is interested… I solved this using the following code…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.