UINavigationController + shouldAutoRotate +没有子类化 [英] UINavigationController + shouldAutoRotate + no subclassing
问题描述
我有一个导航驱动的应用程序。我需要该应用程序旋转。 UINavigationController是窗口中的根控制器/视图。我知道(并且已经体验过为什么)UINavigationController的子类是禁止的。我知道我所要做的就是插入:
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;
}
进入UINavigationController并且它将正常旋转。
into the UINavigationController and it will rotate fine.
所以我的问题是:如何在根视图控制器(UINavigationController)上启用旋转而不进行子类化?
So my question is: how do I enable rotation on the root view controller (UINavigationController) WITHOUT subclassing it?
推荐答案
您需要在 rootViewController
中覆盖此方法,而不是在 UINavigationController
中。
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];
这篇关于UINavigationController + shouldAutoRotate +没有子类化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!