Ios – Show Navigation Bar in Child View Controller

childviewcontrolleriossplitviewuinavigationbaruinavigationcontroller

I am working on an app in which I have to display multiple view controllers side by side (split views). For this purpose I have added views as child view controller.

OBJECTIVE: I want to show navigation bar on one child view controller along with already shown separate navigation bar on parent view controller.

PROBLEM: Navigation bar doesn't get shown on child view controller.

EDIT: I have also set navigation bar of parent view controller as hidden but when child view controller get's called, the navigation bar gets appeared on parent view controller, not on child view controller.

Code to add child view controller is:

    MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:@"MyChildViewController" bundle:nil];

    [self addChildViewController:childViewController];
    [childViewController.view setFrame:CGRectMake(0.0f, 0.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];
    [self.rightContainerView addSubview:childViewController.view];
    [childViewController didMoveToParentViewController:self];

This code is working fine and child view controller gets add perfectly. I want to know is it possible or not?

Thanks in advance.

Best Answer

I solved this problem by myself through following way:

MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:@"MyChildViewController" bundle:nil];
[childViewController.view setFrame:CGRectMake(0.0f, 0.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];

UINavigationController *childNavController = [[UINavigationController alloc] initWithRootViewController:childViewController];
childNavController.view.frame = childViewController.view.frame;

[self addChildViewController:childNavController];
[self.rightContainerView addSubview:childNavController.view];
[childNavController didMoveToParentViewController:self];

Now when I add navigation bar in MyChildViewController, it gets added in child view controller and does not affect navigation bar of parent view controller. The navigationController property of child view controller is also different than navigationController property of parent view controller and both have their own navigation stacks.

Related Topic