AppsDev
AppsDev

Reputation: 12499

Coverting an iPhone targeted app to Universal in Xcode

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

Upvotes: 1

Views: 1235

Answers (3)

Rushabh
Rushabh

Reputation: 3203

You can change only targeted device as iPhone / iPad and you can use the .xib file of iPad:

  if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
    //For navigate to iphone view 
}
else{
     //For navigate to ipad view
}

Reference

Upvotes: 1

Vinod Vishwanath
Vinod Vishwanath

Reputation: 5891

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.).

Upvotes: 3

DD_
DD_

Reputation: 7398

Add 1 more XiB targeted for iPad to each file and during Navigation, select the Xib after checking Device type with the code shown above

Upvotes: 0

Related Questions