I have to add support for iPhone5 to my app. Currently the appdelegate uses a nib that is a UITabBarController, and code like this. Works fine.
[window addSubview:rootController.view];
[window makeKeyAndVisible];
rootController is an instance of UITabBarController.
So I have created a new nib for iPhone5 and changed the code to…
if ([self IsTall])
rootController = [[[UITabBarController alloc] initWithNibName:@"MainWindow_5" bundle:nil] autorelease];
else
rootController = [[[UITabBarController alloc] initWithNibName:@"MainWindow" bundle:nil] autorelease];
[window addSubview:rootController.view];
[window makeKeyAndVisible];
But, the screen is blank with this code, like the nib is not loading.
If I try this I get the correct nibs loading and displaying on the screen but the “MORE” button is not shown and only the first 4 tabs are shown (there are 7 tabs in the tabBarController
if ([self IsTall])
rootController = [[rootController initWithNibName:@"MainWindow_5" bundle:nil] autorelease];
else
rootController = [[rootController initWithNibName:@"MainWindow" bundle:nil] autorelease];
[window addSubview:rootController.view];
[window makeKeyAndVisible];
I also tried…
if ([self IsTall])
[[NSBundle mainBundle] loadNibNamed:@"MainWindow_5" owner:rootController options:nil];
else
[[NSBundle mainBundle] loadNibNamed:@"MainWindow" owner:rootController options:nil];
But this causes a crash on the tab buttons for the nib not declared in the plist under Main
“nib file base name” setting.
Any help very much greatly appreciated. This has stumped me for a couple of days now.
Kind Regards
Rob.
Miscellaneous thoughts:
iPhone 5 is iOS 6. Was your app working under iOS 6 before? If not, get it working for iOS 6 first. My apps came up blank when linked against iOS 6 even if no other changes were made. That’s because view controllers work in a whole different way. So step one is to get the simple of act of launch ironed out for iOS 6. This is particularly true if you are launching into landscape; everything is totally changed in this regard.
Do not add the subview yourself. Just set the window’s
rootViewController. It adds the subview for you.On the whole you should NOT be loading a different nib in any case. You should be using layout to lay out the same interface in such a way that it doesn’t matter whether the screen is tall or not.
Hope something in there will help…
Your second code is totally illegal. Never never never say “init” except in the very same line where you just said “alloc” (except in an initializer, of course).