使用故事板时如何子类化导航控制器? [英] How to subclass Navigation Controller when using storyboards?
问题描述
我在界面构建器中使用Xcode菜单'Editor ... Embed in ... Navigation Controller'。
I'm using storyboards in interface builder using the Xcode menu 'Editor...Embed in...Navigation Controller'.
似乎在iOS 6中你必须将UINavigationController子类化为允许所有方向,
It seems that in iOS 6 you have to subclass the UINavigationController to allow all orientations, with
- (NSUInteger)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskAll );
}
但是如何将UINavigationController与故事板应用程序子类化,因为没有参考代码中的它?
But how do I subclass the UINavigationController with a storyboard app as there is no reference to it in the code?
推荐答案
您可以从故事板中选择导航控制器场景的导航控制器:
You can select the navigation controller scene's navigation controller from the storyboard:
然后使用右侧的身份检查器更改班级:
And then use the identity inspector on the right to change the class:
例如,将Class更改为 MyCustomNavigationController
然后在项目中创建一个名为 MyCustomNavigationController的新类
:
For instance change the "Class" there to MyCustomNavigationController
and then just create a new class in your project called 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
这篇关于使用故事板时如何子类化导航控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!