views:

111

answers:

1

In a custom UIViewController, if I have a member UINavigationController that I initialize with self as the root view, like this:

navController = [[UINavigationController alloc] initWithRootViewController:self];

then presenting a modal dialog does not hide the tab bar at the bottom of the screen. The result is that if the user switches to a different tab while a modal dialog is displayed, when they pop back to the tab that was displaying a modal dialog then subsequent calls to presentModalViewController do not display a modal dialog at all, even if I call dismissModalViewControllerAnimated as a result of the tab switch.

If I initialize the UINavigationController with out setting self as the root controller,

navigationController = [[UINavigationController alloc] init];

then the tab bar is hidden as expected. I've changed things in my program so that this isn't really an issue for me anymore, but I'm not sure that I understand why this is happening. Is it considered bad practice to have a navigation controller with self as the root, if the nav controller is going to be displaying modal dialogs?

A: 

I never added self as root controller

I always have some Controller that gets a NavigationController.view added to itself. And the first ViewController that shall be displayed in the Navigation hierarchy I then add as the rootViewController. It's just another word for "first page" (in the beginning all the naming can be quite confusing).

Example in MyProjectAppDelegate.m:

UITableViewController *startScreen = [[UITableViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:startScreen];
[window addSubview:navController.view];

You also shouldn't mix UINavigationController with UITabBarController, if you want to have a tab bar in a navigationcontroller "page" you can build a custom UITabBarController.

This would show you how http://github.com/wiredbob/NavTab

(I had big problems in understanding all this view/controller nesting myself and this project really made the difference. You could say this was the code I really learned how to programm for iPhone/Mac with :DD )

Allisone
Thanks for the link. I'll take a look at this code!
Tony