views:

15

answers:

0

I created a UIRotatableTabBarController, which is a subclass of UITabBarController.

It is something like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    NSLog(@"Autorotation has been detected!");

    if (self.selectedIndex == 0) {
        return YES;
    } else {
        if (interfaceOrientation == UIInterfaceOrientationPortrait
            || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
            return YES;
        } else {
            return NO;
        }
    }

}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        self.navigationController.navigationBarHidden = YES;

    } else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        self.navigationController.navigationBarHidden = YES;


    } else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        self.navigationController.navigationBarHidden = NO;

    } else if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        self.navigationController.navigationBarHidden = NO;

    }
}

@end

I tried to get the controller from this:

[self.navigationController.viewControllers objectAtIndex:self.selectedIndex];

but it returns me as a null, what should I do to restore the selectedController?? thank you.