Search code examples
objective-cxcode4ios5

shouldAutorotateToInterfaceOrientation is not being called


Hi i am now problem with orientation of viewcontroller. the following is my .h file.

@interface IPad_HomeViewController : UIViewController <UINavigationControllerDelegate>{
    UIAlertView *alertWithYesNoButtons;
}
@property (weak, nonatomic) IBOutlet UILabel *lblStatus;

@end

i implement the following method in .m file.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return NO;
}

then i made a breakpoint. i realized shouldAutorotateToInterfaceOrientation is totally not being called. don't know why it is not being called.

pls advise me. thanks


Solution

  • I think it is because your UINavigationController handles the call. Implement the following to send it back to the viewController.

    - (BOOL)shouldAutorotate
    {
        return [[self.viewControllers lastObject] shouldAutorotate];
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    }
    
    // pre-iOS 6 support
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
    }