1

I have been looking around at tutorials on how to make an iPhone app universal, so that it work on iPad. However when I have tried to implement this I've become a bit stuck since Xcode has changed a fair amount and the tutorials seem out of date. So far I have done the following:

I updated the devices to be set to Universal:

enter image description here

I have also updated my app delegate class like so:

// Set up tab 1
TabOne_ViewController *tabOne = [TabOne_ViewController alloc];
UIViewController *tabOneViewController;

// Set up tab 2
TabTwo_ViewController *tabTwo = [TabTwo_ViewController alloc];
UIViewController *tabTwoViewController;

// Determine which UI to load for each tab
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    tabOneViewController = [tabOne initWithNibName:@"TabOne_ViewController" bundle:nil];
    tabTwoViewController = [tabTwo initWithNibName:@"TabTwo_ViewController" bundle:nil];
}
else
{  
    tabOneViewController = [tabOne initWithNibName:@"TabOne_ViewController(iPad)" bundle:nil];
    tabTwoViewController = [tabTwo initWithNibName:@"TabTwo_ViewController(iPad)" bundle:nil];
}

I have also created two extra .xib files:

  • TabOne_ViewController(iPad).xib
  • TabTwo_ViewController(iPad).xib

Finally I tried to set the class on TabOne_ViewController(iPad).xib to be TabOne_ViewController.h & TabOne_ViewController.m. And also TabTwo_ViewController(iPad).xib to be TabTwo_ViewController.h & TabTwo_ViewController.m. However I wasn't able to do so.

Have I gone wrong somewhere? Are there extra steps I have missed out?

EDIT:

When I was referring to not being able to select the class I mean in IB:

enter image description here

Without being able to link the class to the .xib file I can't link up all of the IBOutlets & IBActions.

  • Could you explain more in detail what "However I wasn't able to do so" mean? What is that is not working? – sergio Dec 23 '11 at 09:13
  • Can you be more clear about what you're exact issue is? Why isn't it working? (I mean, what goes wrong? Can't you select the file, or do you get an error or...?) – CyberK Dec 23 '11 at 09:01
  • I have added further explanation to my question. Sorry for the confusion. –  Dec 23 '11 at 10:04

2 Answers2

1

you go to target click on project,give in summery: Device: "Universal"

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
tabOneViewController = [tabOne initWithNibName:@"TabOne_ViewController" bundle:nil];
tabTwoViewController = [tabTwo initWithNibName:@"TabTwo_ViewController" bundle:nil];
}
else
{  
tabOneViewController = [tabOne initWithNibName:@"TabOne_ViewController(iPad)" bundle:nil];
tabTwoViewController = [tabTwo initWithNibName:@"TabTwo_ViewController(iPad)" bundle:nil];
}

Instead of this code you try this code as follows:

 UIDevice* thisDevice = [UIDevice currentDevice];
if(thisDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
    // iPad
    tabOneViewController = [tabOne initWithNibName:@"TabOne_ViewController(iPad)" bundle:nil];
tabTwoViewController = [tabTwo initWithNibName:@"TabTwo_ViewController(iPad)" bundle:nil];

}
else
{
    // iPhone
    tabOneViewController = [tabOne initWithNibName:@"TabOne_ViewController" bundle:nil];
tabTwoViewController = [tabTwo initWithNibName:@"TabTwo_ViewController" bundle:nil];
}
Rizvan
  • 707
  • 1
  • 6
  • 20
  • after the preprocessor did its job this is pretty much the same code `#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)`. But the first code block will run on iOS < 3.2. – Matthias Bauch Dec 23 '11 at 11:33
1

In the xib you tried to change the class of the View. But you have to change the class of File's Owner

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247