views:

395

answers:

2

I have a navigation driven app. I need that app to rotate. The UINavigationController is the root controller/view in the window. I know (and have experienced why) it is a no-no to subclass UINavigationController. I know all i have to do is insert:

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

into the UINavigationController and it will rotate fine.

So my question is: how do I enable rotation on the root view controller (UINavigationController) WITHOUT subclassing it?

+1  A: 

Your UINavigationController inherits from UIViewController - why would using the method you show be a bad thing? It is perfectly legitimate to use a super's method and is the only way I have ever supported rotation in a UINavigationController. Wouldn't subclassing be when you inherit from UINavigationController (and override that method to do something else without calling the super method?)

Adam Eberbach
I had heard that UINavigationController should never be subclassed (source: http://www.iphonedevsdk.com/forum/iphone-sdk-development/5829-uinavigationcontroller-subclassing.html). So basically my question was how to do what you are saying without subclassing.
ACBurk
UINavigationController is always a subclass of UIViewController. That isn't "subclassing" (or at least not the in the sense of the subclassing Apple say you should avoid), which is when you further inherit from a class and use the new class to override methods in the superclass. Almost every object you use is a subclass - in developer documentation check the "Inherits from" line at the top of each page. If a superclass, such as UIView, has a method you want to use it is fine to go ahead and use it.
Adam Eberbach
I know UINavigationController is a subclass of UIViewController. What they are saying is you shouldn't subclass UINavigationController and create your own UICustomNavigationController (where you would override shouldAutoRotate).
ACBurk
+2  A: 

You need to override this method in your rootViewController, not in UINavigationController.

UIViewController *rootViewController = [[MyRootViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[rootViewController release];
Aleksejs
hum, I thinking there should be some way to do it in a central location but from what I've been reading on the Apple Dev Forum and your answer, seems it should just be done on all viewcontrollers. Helps a TON. Thanks.
ACBurk