I have a project that was intended to be an iPhone app in first instance, but now I want it to also support iPad. I have changed project's target from iPhone to Universal, but I dont know how to manage both nib versions I need now, already having nibs designed for iPhone. I tried by loading same viewControllers with different nibs according to the device, but Im not allowed to set more than one interface control to the same outlets. Any help? I have Xcode 4.4
It's pretty easy.
For your storyboard files, just include the _iPad
and _iPhone
suffixes.
For example, if the original storyboard name is MyStoryboard.storyboard
, you'll now have MyStoryboard_iPad.storyboard
and MyStoryboard_iPhone.storyboard
. You can also set the storyboard file for each device under the summary view of the project.
Then, for the.xib files, include the ~iPhone
and ~iPad
suffixes.
ViewController.xib
becomes ViewController~iPad.xib
and ViewController~iPhone.xib
To start off, you can just create a duplicate if your existing .xib files and rename them to have the iPad and iPhone suffixes. Then alter the contents of each .xib as needed.
As for the .m code, you can check device type and branch your code. My approach is to define macros that identify device type, like this:
#define isDeviceIPad (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
#define isDeviceIPhone (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
Then I just use these macros(which return bool values) to write code that's specific to a device type(such as placement or dimensions of a particular view etc.).