Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to subclass Navigation Controller when using storyboards?

I'm using storyboards in interface builder using the Xcode menu 'Editor...Embed in...Navigation Controller'.

It seems that in iOS 6 you have to subclass the UINavigationController to allow all orientations, with

- (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?

like image 606
SPA Avatar asked Oct 18 '12 09:10

SPA


People also ask

How do I use navigation controller in storyboard?

Drag a Button from the Object Library and place it on top of the View Controller. Change the title to “Show First View Controller”. Next, drag another View Controller to the Storyboard and place it next to the root view controller.

How do I change the initial view controller in storyboard?

Specifying the Initial View ControllerOpen Main. storyboard and select the Tab Bar Controller Scene. On the right, select the Attribute inspector. You'll find a checkbox named Is Initial View Controller.

How do you add a segue between two view controllers in a storyboard?

To create a segue between view controllers in the same storyboard file, Control-click an appropriate element in the first view controller and drag to the target view controller. The starting point of a segue must be a view or object with a defined action, such as a control, bar button item, or gesture recognizer.

How do I add navigation bar in view controller in storyboard?

Go to the Storyboard. Select the View Controller and in The Editor menu select Embed in -> Navigation Controller. Next, drag a Bar Button from the Object Library to the left side of the Navigation Bar and name it "Left Item". Repeat this for the right side and name it "Right Item".


1 Answers

You can select the navigation controller scene's navigation controller from the storyboard:

enter image description here

And then use the identity inspector on the right to change the class:

enter image description here

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
like image 142
mattjgalloway Avatar answered Nov 15 '22 20:11

mattjgalloway