copenndthagen
copenndthagen

Reputation: 50790

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.

Upvotes: 1

Views: 1463

Answers (3)

user1002909
user1002909

Reputation: 174

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]
}

Upvotes: 2

ott--
ott--

Reputation: 5722

You could create the ViewController programmatically. Just query the width and height of the device. Then place your items according those values.

Upvotes: 0

Mr. Berna
Mr. Berna

Reputation: 10655

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.

Upvotes: 2

Related Questions