I have overridden my UINavigationController to implement these methods:
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate]
It seems you are confusing what to return in shouldAutorotate. Use the following code as an example.
Since iOS is making a call into your app's shouldAutorotate in response to an event from the accelerometer, it already knows the new orientation; if your app answers 'YES`, iOS could then check the current orientation against the list of supported ones, and come up with a decision without your app querying for the current orientation.
// iOS 6
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Also, You can let the view controller that presents your modal view controller inform it of rotation. Use: presentViewController:animated:completion: to present the view controller. presentModalViewController:animated: is deprecated if by chance you are using it.
If you add application:supportedInterfaceOrientationsForWindow:, make sure to follow the code guideline below. The documentation states that if you implement supportedInterfaceOrientations on a VC it should override the app delegate. However, people have noticed it makes a difference as to how you add the rootViewController to the main window.
Use:
window.rootViewController = viewController
instead of:
[window addSubview:viewController.view];