8

我在使用Xcode菜單'編輯器...嵌入...導航控制器'的界面生成器中使用故事板。如何在使用故事板時子類化導航控制器?

看來,在iOS 6中,你有子類的UINavigationController,讓所有的方向,與

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

但是我怎麼繼承了UINavigationController的一個故事板的應用程序,因爲在代碼中它沒有提及?

+0

在Interface Builder中,在右側選擇的UINavigationController然後在身份Inspector選項卡3,變更類的CustomNavigationController名稱。 – Atif

+0

UINavigationController支持iOS6中的所有方向。 –

回答

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 
+1

優秀!感謝那 – SPA

相關問題