1

Possible duplicate:

How to make xib compatible with both iphone 5 and iphone 4 devices
Can I use two xibs with one viewcontroller - re: porting to iPhone 5

I have developed an iPhone app which now I'm trying to update giving it iPad and iPhone5 support. I now there are lots of posts talking about how to handle this but none of them are working for me. 3.5'' iPhones and iPads load the xib they need but 4'' iPhone doesn't (although in simulator works fine), so here is how I handle it:

First of all I create three different xib files for each viewController (ViewController.xib, ViewController~ipad.xib and ViewController-568.xib). In the 4'' xib one I set the size of the view as "Retina 4 Full Screen".

Then I have used this to load the appropiate xib. It also may be relevant to say that in the AppDelegate I set the didFinishLaunchingWithOptions like this:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     NSString *nibName = [UIViewController nibNamedForDevice:@"ViewController"];
     self.viewController = [[BPViewController alloc] initWithNibName:nibName bundle:nil];
     UINavigationController *navCont = [[UINavigationController alloc]                   initWithRootViewController:self.viewController];
     self.window.rootViewController = navCont;
     [self.window makeKeyAndVisible];
     self.viewController.navigationController.navigationBar.barStyle = UIBarStyleBlack;
     return YES;
}

As I said it works like a charm in the simulator but in real device only iPad's and 3.5'' xib are load properly. The iPhone5 still is showing the up and down black bar...

Community
  • 1
  • 1

1 Answers1

0

You appear to be using the wrong suffix on your nibs/assets, use -568h@2x instead of -568h.

Alternatively i always switch various iOS assets / positions in code using:

if([ [ UIScreen mainScreen ] bounds ].size.height == 568 )
{
    //iPhone 5.0 specific code
}
else
{
    //None iphone 5 code
}

Its also worth noting at this stage that using more nib files to do this will result in a bigger .IPA. So its worth reading up on how autolayout works and going for that approach to keep executable size down.

Dev2rights
  • 3,469
  • 3
  • 25
  • 42
  • First of all thanks for your response, I know about autolayout but my app must be iOS5 compatible so I'm afraid it's not an option. I also have tried to use mainScreen size to load one nib or another. It works fine when I debug it on simulator but for some reason don't works in real iPhone5 device **EDIT**: I have changed all nibs and assets to use -568h@2x but there's no difference – Miquel_Alvarado May 19 '13 at 12:32
  • You are aware that iphone 5 was released after iOS 6 was launched? Meaning the nomenclature for those suffixes hadn't been released on older versions of the OS. You might be trying to do something that isn't possible. Loading seperate NIB's using screen dimensions is possible as i have done it in the past irrespective of what version of the OS you are using, you must have something else wrong here. – Dev2rights May 19 '13 at 12:46
  • **SOLUTION**: The project is old (iPhone5 was not released yet) so when I created it the project didn't add the "Default-568h@2x.png". My assets have the correct sufix, but somehow your answer was right, Thanks! – Miquel_Alvarado May 19 '13 at 14:15