Reputation: 1022
I've created a new "Tab Bar project" with the new Xcode 4.2. The "new" way to work with UITabBar is different: Xcode doesn't create a xib file (with the UITabBarController), but it does everything via code. Ok, let's do it.
So my code in didFinishLaunchingWithOptions
is this:
UIViewController *viewController1, *viewController2, *viewController3;
UINavigationController *nav1, *nav2, *nav3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[gemboy_iphone alloc] initWithNibName:@"vc1" bundle:nil];
viewController2 = [[concerti_iphone alloc] initWithNibName:@"vc2" bundle:nil];
viewController3 = [[discografia_iphone alloc] initWithNibName:@"vc3" bundle:nil];
nav1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
nav2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
nav3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
}
else {
//same thing for the iPad version
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nav3, nil];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:self.splash.view];
[self.window makeKeyAndVisible];
return YES;
And it works.
My three .m files vc1.m, vc2.m and vc3.m (and also my iPad UIViewControllers) has this method
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
The problem is that when I rotate the iPhone, it rotates only the status bar, and not the TabBarController!
Do you know why? Thanks
Upvotes: 1
Views: 1287
Reputation: 7703
You absolutely do not have to subclass UITabBarController, nor should you.
A tab bar controller will auto-rotate just fine IF all of its view controllers implement shouldAutorotateToInterfaceOrientation and return YES for the same orientations.
If you create a new project in Xcode 4.2 with the Tabbed Application template, you will see that it auto-rotates just fine.
Upvotes: 2