简体   繁体   English

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

[英]How to subclass Navigation Controller when using storyboards?

I'm using storyboards in interface builder using the Xcode menu 'Editor...Embed in...Navigation Controller'. 我在界面构建器中使用故事板使用Xcode菜单'Editor ... Embed in ... Navigation Controller'。

It seems that in iOS 6 you have to subclass the UINavigationController to allow all orientations, with 似乎在iOS 6中你必须将UINavigationController子类化为允许所有方向

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

But how do I subclass the UINavigationController with a storyboard app as there is no reference to it in the code? 但是,如何将UINavigationController与故事板应用程序子类化,因为代码中没有对它的引用?

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: 然后使用右侧的身份检查器来更改类:

在此输入图像描述

For instance change the "Class" there to MyCustomNavigationController and then just create a new class in your project called MyCustomNavigationController : 例如,将“Class”更改为MyCustomNavigationController ,然后在项目中创建一个名为MyCustomNavigationController的新类:

MyCustomNavigationController.h : MyCustomNavigationController.h

#import <UIKit/UIKit.h>

@interface MyCustomNavigationController : UINavigationController
@end

MyCustomNavigationController.m : MyCustomNavigationController.m

@implementation MyCustomNavigationController

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

... any other methods you want ...

@end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在子类中实现导航控制器? - How to implement a navigation controller in a subclass? 不确定如何在使用故事板时正确地子类化UIApplication - Not sure how to properly subclass UIApplication while using storyboards 使用导航控制器时如何跳过2个视图 - How to skip 2 views when using navigation controller iPhone在情节提要中展示和关闭导航视图控制器? - iPhone presenting and dismissing navigation view controller in storyboards? 如何设置以编程方式创建的TableView的子类? (没有情节提要) - How to set the subclass of a TableView that was created programmatically? (no storyboards) ios:如何使用StoryBoards从ViewController打开Tab Bar控制器 - ios: How open Tab Bar controller from ViewController using StoryBoards 如何使用故事板呈现启动/登录视图控制器 - How to present a splash/login view controller using storyboards 使用情节提要板ioS5时从视图控制器移动到选项卡栏控制器 - Moving from a view controller to a tab bar controller when using storyboards ioS5 使用情节提要板时如何在appDelegate中获取指向viewController的指针 - How to get a pointer to a viewController inside the appDelegate when using storyboards 使用导航控制器时如何初始化视图 - How Do I Initialize a View When Using Navigation Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM