Reputation: 2819
I am building an iOS application where I have multiple view controllers made from .xib files. The entire application will allow both portrait and landscape orientations, but the first three view controllers will be portrait ONLY. The screen after that will be in landscape ONLY. For this reason, I have created two subclasses of UINavigationController, one to restrict the first three in portrait mode, and the last one in landscape mode.
At the moment, I am able to display the first view controller, and lock it in portrait mode. Here is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewControllerA *testViewA = [[ViewControllerA alloc] initWithNibName:@"ViewControllerA" bundle:nil];
PortraitNavigationController *navController = [[PortraitNavigationController alloc] initWithRootViewController:testViewA];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
The code for PortraitNavigationController (which subclasses UINavigationController) contains one method, and looks like this:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
Inside ViewControllerA, I have a button which, when pressed, calls ViewControllerB (which is also to be locked in Portrait mode. The code that I have inside the button action method is as follows:
- (IBAction)buttonAction:(id)sender {
PortraitBViewController *testBView = [[PortraitBViewController alloc] initWithNibName:@"PortraitBViewController" bundle:nil];
PortraitNavigationController *portraitNav = [[PortraitNavigationController alloc] initWithRootViewController:testBView];
//How do I push this new view Controller on to the stack?
}
As you can see in my comment above, how would I push the next view controller on to this stack (and then of course, pop to return back to the previous one)? The problem I have is that like a conventional app, I would like to have a stack of view controllers, except in my case I want to use a custom UINavigationController class.
Normally, I would use the reference self.navigationController to push the next view controller on to the stack, but in this case, because I'm using a custom navigation controller, it looks like I will have to create a new reference to the custom navigation controller in EACH view controller that I'm using. If this is the case, then that means I'm creating a new rootViewController each time, which means essentially, I'll have three different stacks (of one view controller each), instead of one stack of three view controllers.
How can I use the same reference to the custom UINavigationController to call push/pop each of the view controllers? Then finally, how would I then connect these view controllers to another one which is using a different navigation controller, yet keep everything on the same stack?
Upvotes: 0
Views: 80
Reputation: 385
Your life will be very difficult if you use multiple UINavigationControllers. You should specify which orientations are supported in the UIViewControllers and not in the UINavigationControllers.
Upvotes: 2