Reputation: 9120
I have the following layout on my story board:
When I click on the button I load the blue view controller:
- (IBAction)blue:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
BlueViewController *blue = [storyboard instantiateViewControllerWithIdentifier:@"BlueViewController"];
[self presentViewController:blue animated:YES completion:nil];
}
The blue view controller has navigation bar embed. But doesn't show on either the blue viewcontoller or the pink view contoller:
My question to you guys is what I'm doing wrong? or why does the view controller is not showing ?
Upvotes: 0
Views: 151
Reputation: 46
If you want to present on a view controller then you have to add a custom view in in top of your controller cz it's on the your navigation controller. If you push a controller then you don't need the above. You will find the same navigationbar to all. Cz It's within your navigation controller stack.
Upvotes: 0
Reputation: 11201
Give the navigation controller for blue VC a storyboard ID, and present that instead of blue VC.
If you present a VC, even though it has a navigation controler it doesnt show up as you present only the view cotroller.
- (IBAction)blue:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *blueNavVC = [storyboard instantiateViewControllerWithIdentifier:@"BlueViewControllerNavigationController"];
[self presentViewController: blueNavVC animated:YES completion:nil];
}
And when you want to move from blue to pink, you need to push to pink controller as pink is part of the blue navigation controller stack!
Upvotes: 2