How to push UIViewController with replaced UINavigationController
I have a custom UINavigationController that draws a custom background. That navigation controller is already set when accessing self.navigationController on the root view controller. Now what I'd like to do is to push a new view controller but replace the navigation controller in the new view controller to a default one (without the custom background).
Basically the new view controller is presenting an image with the navigation bar being translucent. Because it reuses the navigation controller (with the custom background) from the root view controller, the end effect is translucent navigation bar with custom background.
I know I could replace the navigation bar when presenting the new view controller as a modal view. But can I replace it when pushing the new view controller?
I tried something like this but this code has no effect:
LTImageViewController* controller = [[LTImageViewController alloc] init]; UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:self]; [navController pushViewController:controller animated:YES];
While pushing a view controller in UINavigationController it creates an stack, and i think we can not push an navigation controller in another.
You can do one thing show your viewController modally and change the TransitionStyle to UIModalTransitionStyleCoverVertical
You can't just push a view controller onto any old navigation controller's stack. (Well, you can, but you won't get very far.) The nav controller should be the root view controller for the app's window. If you want to use your custom navigation controller, you should replace the existing navigation controller with your custom version. You'd do something like:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; delegate.window.rootViewController = [[MyCustomNavController alloc] init];