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

时间:2012-10-18 09:10:14

标签: iphone uinavigationcontroller storyboard uiinterfaceorientation subclassing

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

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

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskAll   );
}

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

1 个答案:

答案 0 :(得分:21)

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

enter image description here

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

enter image description here

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

<强> MyCustomNavigationController.h

#import <UIKit/UIKit.h>

@interface MyCustomNavigationController : UINavigationController
@end

<强> MyCustomNavigationController.m

@implementation MyCustomNavigationController

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

... any other methods you want ...

@end