Migrating to Universal app (iPhone/iPad)

I have an old iPhone app and now want to migrate it to an iPad app... So I have 1 XIB with some UIWebView and iAd views...

How do I convert it to an uinversal app...I have only changed Devices to Universal....I mean will just adding a new xib say DetailController-ipad.xib work i.e. for iPad it would automatically take it ?

Actually in my code, I have;

DetailController *detailController = [[DetailController alloc] initWithNibName:@"DetailController" bundle:nil];

So would the same old DetailController.xib not be pushed ALWAYS ?

What changes do I need to make ?

Please help.

Answers


At the point of loading the nib, ask the system what type of device you are running on and then load the appropriate nib file. Use something like this:

DetailController *detailController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    detailController = [[DetailController alloc] initWithNibName:@"DetailController" bundle:nil];
} else {
    detailController = [[DetailController alloc] initWithNibName:@"DetailController-ipad" bundle:nil];
}

You may also want to do something different with your detail view controller in the different interface idioms, such as put the view controller in a UINavigationController on the iPhone and a UISplitViewController on the iPad.

A further option is to have a separate DetailController implementations for iPhone and iPad. Your interface may be very similar in both interface idioms, and one DetailController would be better. Or you may have significantly different interfaces for the iPhone and iPad versions of your app, where a iPhoneDetailController and a iPadDetailController would make more sense. For example the smaller screen of the iPhone may necessitate the use of a UINavigationController, but the larger iPad screen can contain the entire interface on one screen.

Edit responding to a comment:

The Interface Builder portion of Xcode sets the interface idiom at creation of the .xib files, blocking conversion of a .xib from iPhone format to iPad format. Make a new interface file for the iPad .xib. You can copy and paste the elements from your iPhone .xib to your iPad .xib, then reconnect the outlets and adjust sizing and placement.


if you load your GUI programmatically, let's using these to check the device is iPhone or iPad.

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  // The device is an iPad running iPhone 3.2 or later.
  // [load appropriate iPad nib file]
}
else {
  // The device is an iPhone or iPod touch.
  // [load appropriate iPhone nib file]
}

Need Your Help

ImageButton in ViewBinder doesn't work

android imagebutton android-viewbinder

I created a ViewBinder, to hold my items in a ListView, which get its contents from a SimpleCursorAdapter and in this there's a ImageButton. I successfully get the list but the ImageButton just won't