1

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.

copenndthagen
  • 49,230
  • 102
  • 290
  • 442
  • Check out this SO post - http://stackoverflow.com/questions/7011309/converting-an-iphone-app-to-a-universal-app – 5StringRyan Nov 30 '11 at 18:29

3 Answers3

2

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]
}
user1002909
  • 174
  • 2
  • 11
2

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.

Mr. Berna
  • 10,525
  • 1
  • 39
  • 42
  • Ok..Thanks a lot for that...Actually in my app, there are 2 VCs; ListController and DetailController....The ListController only has a table view, which is stretching automatically on the iPad....That is the reason, I am only looking to update DetailController (which has a Webview and iAd) that does not scale automatically for iPad size... – copenndthagen Dec 01 '11 at 06:46
  • My only question to you now is, for the DetailController-ipad.xib, should I add/create it manually OR can I convert it from the existing iPhone view (DetailController.xib) given that it has only Webview and iAd....Will I get to see the outlets automatically on this new ipad.xib ? – copenndthagen Dec 01 '11 at 06:48
0

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

ott--
  • 5,642
  • 4
  • 24
  • 27