Reputation:
A very simple question: My iPhone app has a button in MainWindow.xib. When I press that button a new view should load. That view will contain a nice navigation controller. How can I do that?
All the information I've found is about apps that start directly from a navigation controller. I need to load the nav controller after a button click.
Many thanks!
Upvotes: 4
Views: 5292
Reputation: 96937
Another way to go about this is to simply hide the navigation bar in your root controller:
- (void) viewDidLoad {
...
if (![self.navigationController isNavigationBarHidden])
[self.navigationController setNavigationBarHidden:YES animated:NO];
...
}
That way, you have a nice, clean root controller with no navigation bar in the way.
When you click on a button in your root controller, you simply push in a new view and un-hide the navigation bar:
- (IBAction) pushAnotherView:(id)sender {
AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
if ([self.navigationController isNavigationBarHidden])
[self.navigationController setNavigationBarHidden:NO animated:YES];
[anotherViewController release];
}
If you have some notification or other action that brings you back to the root view controller, just hide the notification bar again:
- (void) viewWillAppear:(BOOL)animated {
if (![self.navigationController isNavigationBarHidden])
[self.navigationController setNavigationBarHidden:YES animated:YES];
[super viewWillAppear:animated];
}
Upvotes: 2