Selective autorotation in a UINavigationController In a current project I needed to enable/disable autorotation of the UI to specific UIView's. I looked around and did not find a working solution that fitted my case and returning NO in

shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation


method did not work as it seems to get overridden by the value returned by the UIView in which the UINavigationController resides in. 

So I now keep track of which view is currently being pushed into the stack by using the delegate method:

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated


and then check if the current view is my "don't rotate view" in

shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation


and return NO if that's the case, works perfectly.

In my code it looks like this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (currentView == [DimensionConversionViewController class]) {
        return NO;
    }
    return YES;
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    currentView = [viewController class];
}


This looks more like a hack to me. Has anybody come across the same problem and solved it in another/more elegant way? As stated above this seems to be the only way to achieve this.
First of all you could skip storing the current view controller in a variable. And instead of checking for the correct class you could delegate your shouldAutorotateToInterfaceOrientation: to the current visible one in the navigation controller.

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // assumes you've got access to the navigation controller here
    UIViewController *visibleController = navigationController.visibleViewController;

    return [visibleController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}