6

I made an iPhone app long ago and I'm now thinking of making it a universal app, but I was wondering if I could use Storyboards for making the iPad version, so for the iPhone it would load a MainWindow.xib and for the iPad it would load a MainStoryboard file. Is this possible?

  • 1
    I think, unless the app is very complex, you would be better off just making it all storyboard. That way all the transitions would be the same, and your code would be a lot cleaner. – nycynik Oct 31 '12 at 23:59
  • That's the thing, the app is quite complex, and I don't think I would do it all over again for the iPad if Storyboards wasn't available, but before I rush into anything I need to know if I'm able to do that. – user1790012 Nov 01 '12 at 00:06

3 Answers3

3

Yes, but you actually have to make two separate storyboards (1 for iPhone and 1 for iPad).

In the iPhone storyboard, just drag your mainwindow.xib into the middle of the rootViewController and make sure it goes full-screen.

Then, you can do whatever you want with your iPad storyboard.

Make sure that your two storyboard files are linked correctly in your project summary though!

Gazzini
  • 728
  • 8
  • 19
3

Gazzini is right and got his answer in first while I was doing research to confirm that this was true & relatively straightforward before I got to type in my own answer. So +1 to him.

You don't need two separate storyboards though. You just need one storyboard for one architecture and your XIB files for the architecture you already support.

Here is a screenshots that might help show you what I did in my own test project:

Yes It Is Possible

Simply edit the plist of your application to use a "nib" file for the specific architecture you already have XIB files for, and then specify storyboards for the new architecture.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Thank you very for your answer too, but doing some research I found that in order to submit an app to the App Store, in my info.plist I can only set either NSMainNIBFile or UIMainStoryboardFile. I found this in the Information Property List Key Reference Guide where it says "NSMainNIBFile: This key is mutually exclusive with the 'UIMainStoryboardFile' (page 77) key. You should include one of the keys in your Info.plist file but not both." – user1790012 Nov 02 '12 at 01:28
0

It will be simpler for you to use a storyboard on iPad and nibs on iPhone if you don't set Main Interface (NSMainNibFile in Info.plist) or a Main Storyboard (NSMainStoryboardFile in Info.plist).

Instead, move your app delegate out of MainWindow.xib and let UIApplicationMain instantiate it by passing its class name as the fourth argument to UIApplicationMain in main. Make the app delegate the File's Owner of MainWindow.xib.

In your app delegate's application:didFinishLaunchingWithOptions:, you can inspect the interface idiom.

If the interface idiom is iPhone, load MainWindow using -[NSBundle loadNibNamed:owner:options:].

If the interface idiom is iPad, create your window, load MainStoryboard using +[UIStoryboard storyboardWithName:bundle:], instantiate its initial view controller with -[UIStoryboard instantiateInitialViewController], and set that view controller as your window's root view controller.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848