views:

40

answers:

2

I'm having what appears to be a simple problem. I declare a navigation controller but the navigation bar that comes up is not displayed at the top of the page.

http://sphotos.ak.fbcdn.net/hphotos-ak-snc3/hs410.snc3/24784_889732028002_28110599_54506042_4580563_n.jpg

I declare the navigation controller like so...

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:setupViewController];

[self.view addSubview:navController.view];

Any ideas?

A: 

You shouldn't really add a NavigationController as a subview to a view like this. It's totally defeating the purpose. You need to create your UINavigationController using initWithRootViewController and then show it. Try something like:

UINavigationController *controller = [[UINavigationController alloc]initWithRootViewController:setupViewController];
[self presentModalViewController:controller animated:YES];
[controller release];

(you might want self.navigationController or something else in the presentModalViewController line, depending on what "self" is)

marcc
+1  A: 

marcc is right in saying that you should not add the navigation controller view as a subview to your view. In fact the hierarchy must be created such that your view controller is the root view controller in your navigation controller.

The hierarchy of view controllers is usually constructed as: window -> tab bar controller -> navigation controller -> view controller.

The tab bar controller and navigation controller are definitely optional.

You can push and pop view controllers from your navigation controller by using the pushViewController:animated and popViewController:animated methods.

Hetal Vora