0

I have been stuck on this for a few days now and it is killing me... In my viewDidLoad event, I am trying to programmatically add a full screen UINavigationController to a subview of my view controller. So far, I have only succeeded in doing two things...

1) Only a grey screen shows up
OR
2) I get something that resembles a navigation controller added to the view controller, instead of being my navigation controller from a XIB it is just a generic one... even though I loaded from the XIB. Oddly enough it is always shifted 25 pixels downward and slightly cut off.

I have read every single link on google and I can't seem to figure this out. I just created a new viewcontroller... added a UINavigationController to it... try to load that view controller and it messes up.

Any help is greatly appreciated!!!!

1 Answer 1

1

Instead of having the UINavigationController be a child of some other view controller, make the UINavigationController the root controller itself. The navigation controller is one of the special "container" view controllers, and it generally wants to own the whole screen and be at the root of the controller hierarchy (except in certain circumstances).

Try something like this:

UINavigationController * rootNavController = [[UINavigationController alloc] initWithRootViewController:myRootControllerInTheNavController];
[window addSubview:[rootNavController view]];

Which will obscure any existing views with the nav controller (those existing things will still be there when you -removeFromSuperview the nav controller's view). The nuclear option is to set your UIWindow's rootViewController property with the nav controller, but it sounds from your comment that this may not be what you want to do here.

Possibly a cleaner approach: If it accomplishes what you want, I believe you could also take your nav controller and present it modally (see docs for uiviewcontroller) from whatever the current view controller is. Set the transition appropriately, and while you're in the nav stack, the nav controller will be visible.

Sign up to request clarification or add additional context in comments.

6 Comments

My entire application doesn't depend on this controller... just a couple pages. How do you go about making it the root? I would need to hand it control from the controller that owns the screen, I guess???
Thanks for the great response!!! The prsenting modally is exactly the kind of thing that i would like to do but it is what is giving me a grey screen... let me show you a cut of code: LiteViewController *lite = [[LiteViewController alloc] initWithNibName:@"LiteViewController" bundle:nil]; [self presentModalViewController:lite animated:YES]; LiteViewController is my controller with my UINavigationController... it does not have a window or view attached to it - it only has a child view attached, not a main one.... maybe that is why it is going grey.
Is LiteViewController a subclass of UINavigationController? In this case, it should be. Lite shouldn't be a generic controller with a child nav controller.
Opps, It seems that LiteViewController was a subclass of UIViewController... let me change that and try a few things... great catch.
Well that made progress... the prsent modal still shows a grey screen; however, if I do addsubview it is loading a navigation controller to the view but it is not creating it from the nib... it is just a generic navigation controller. ------------- LiteViewController *lite = [[LiteViewController alloc] initWithNibName:@"LiteViewController" bundle:nil]; [self.view addSubview:lite]; ---------- Sorry I do not know how to do carriage returns in comments.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.