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.
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.
add Navigation bar like this
It will be appear in your all view controller
Another way to do:
Put this code into didFinishLaunchingWithOptions method in appdelegate.m file.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ECViewController * ec = [[ECViewController alloc] initWithNibName:@"ECViewController" bundle:nil];
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:ec];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
Add a Nib file(ECViewController) by simply following these steps:
1: Right click in project root
2: Add new file
3: Go to user interface.
4: Select view
5: Give it name same as your view controller name i gave ECViewController in my case.
Click on newly created nib file
Click on file owner fist yellow box on left side. make an connection with view by simple dragging with control keyword.click on view when popup appear.
Now goto identity inspector (fourth section from staring in left side).
Write your class name in Class name textBox appeared.
By this you can able to open an xib in iOS7 if you don't want to use storyboard.
Now if you need view controller with navigation controller.
Then open your view controller by this way.
ECViewController1 *v = [[ECViewController1 alloc]initWithNibName:@"ECViewController1" bundle:nil];
[self.navigationController pushViewController:v animated:YES];
Its too late for this edited answer, Hope it will help someone other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With