开发者

UINavigationController + shouldAutoRotate + no subclassing

开发者 https://www.devze.com 2022-12-29 08:26 出处:网络
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 UINavigatio

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?


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];


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?)

0

精彩评论

暂无评论...
验证码 换一张
取 消