0

I am little bit confused about creating universal application for iOS devices using Xcode 4.3 , later versions (Xcode 4) have separate folder classes for this, but how will we make this using newest version of Xcode?

Thanks in advance

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
Neeraj Neeru
  • 570
  • 8
  • 28
  • 1
    What is your exact problem? Creating a universal app or making it universal in context of implementation? – Parth Bhatt Apr 10 '12 at 06:01
  • @parth the problem is , i need to develop a universal app and to know how will i load both .xib files by detecting the device.i know selecting device family, problem is the inner part, detecting the device and loading correspondent .xib? – Neeraj Neeru Apr 10 '12 at 11:26
  • I have edited my answer. Please check the **EDIT** section of my answer. – Parth Bhatt Apr 10 '12 at 12:04

3 Answers3

2

just select device family as universal while creating the project,

watch this screen shotenter image description here

Charan
  • 4,940
  • 3
  • 26
  • 43
  • sorry, my question is not in the right way.. actually i know how to select device family, problem is the inner part, detecting device and loading correspondent .xib ! i have tried but got some errors. will you please tell me the correct way to load .xib – Neeraj Neeru Apr 10 '12 at 11:29
2

I don't think this has changed in Xcode 4.3 compared to previous versions of Xcode 4.* , but though you have a doubt refer to my answer below.

If you want to create a new project as Universal App then select Universal in Device Family in below image:

enter image description here

Or if you are trying to convert an existing iPhone or iPad app to Universal app then select Devices as Universal from Target Settings- > Summary Tab, set Devices to Universal:

enter image description here

Hope this helps you.

EDIT:

Let us suppose View Controller name is YourViewController

Let us suppose name of iPad XIB is YourViewController-iPad.xib and iPhone xib name is YourViewController.xib

YourViewController *yourViewController;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //This is iPad 
{
    // iPad-specific interface here
    yourViewController = [[YourViewController alloc] initWithNibName:@"YourViewController-iPad"  bundle:nil];
}
else // This is iPhone or iPod
{
    // iPhone and iPod touch interface here
    yourViewController = [[YourViewController alloc] initWithNibName:@"YourViewController"  bundle:nil];
}

Let me know if you need more help.

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
  • @NeerajNeeru: I have edited my answer. Please check the **EDIT** section of my answer. I think by this added code you will be able to distinguish devices iPad and iPhone and based on that you can load your XIBs. Now if this has helped you, accept the answer. – Parth Bhatt Apr 10 '12 at 12:07
1

well you need to create two xib's, one for iPhone and one for iPad and just use

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){

here open your iPad xib

} else {

here open your iPhone xib

{
Charan
  • 4,940
  • 3
  • 26
  • 43