If you are developing for IOS 5 using storyboards this will help i had the same issue. Typically before storyboards we might add the TabBarController to a uiview or in the appdelegate. With storyboards the storyboard view does not always have to be connected to a viewcontroller.
To fix do this
Add a new class file objective-c class in the subclass field type UITabBarController
1 - In the storyboard select the tab bar controller view
2 - Under custom class change UITabBarController to your newly created class name, i called mine MainTabBarViewController
3 - In you newly created class change this
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
to
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
return YES;
return NO;
}
Basically what is happening is you are creating a structure in Interface Builder, but that only gets you part of the way. In this case you will still have to create the companion code. This confused me at first, because i'm used to building views up from scratch using .xib, and would typically configure the tabbarcontroller from the appdelegate.
Also you can conditionally control each of these like this
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
return NO;
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return NO;
if (interfaceOrientation == UIInterfaceOrientationPortrait)
return YES;
if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
return YES;
Just return yes for what you want, return no for what you don't want. or to accept everything return yes .