Can you make a universal app using both MainWindow.xib for the iPhone and Storyboard for the iPad?
-
24-07-2021 - |
Question
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?
Solution
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!
OTHER TIPS
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:
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.
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.