如何在使用故事板时继承Navigation Controller?

SPA*_*SPA 8 iphone storyboard uinavigationcontroller subclassing uiinterfaceorientation

我在界面构建器中使用故事板使用Xcode菜单'Editor ... Embed in ... Navigation Controller'.

似乎在iOS 6中你必须将UINavigationController子类化为允许所有方向

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskAll   );
}
Run Code Online (Sandbox Code Playgroud)

但是,如何将UINavigationController与故事板应用程序子类化,因为代码中没有对它的引用?

mat*_*way 21

您可以从故事板中选择导航控制器场景的导航控制器:

在此输入图像描述

然后使用右侧的身份检查器来更改类:

在此输入图像描述

例如,将"Class"更改为MyCustomNavigationController,然后在项目中创建一个名为的新类MyCustomNavigationController:

MyCustomNavigationController.h:

#import <UIKit/UIKit.h>

@interface MyCustomNavigationController : UINavigationController
@end
Run Code Online (Sandbox Code Playgroud)

MyCustomNavigationController.m:

@implementation MyCustomNavigationController

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

... any other methods you want ...

@end
Run Code Online (Sandbox Code Playgroud)