I am adding a UIViewController as the root controller for a UINavigationController (see below)
UIViewController *myUIViewController = [[TableController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myUIViewController];
My question is with regard to setting the navigationItem property on the UIViewController
[[self navigationItem]setTitle:@"Name"];
When you do this what is the relationship between setting this on the UIViewController and how it is picked up by the UINavigationController. My understanding is that the navigation bar is on the UINavigationController and I have been wrongly trying to set it there.
Does the UINavigtion开发者_如何转开发Controllers navigation bar look at the UIViewControllers navigationItem to get its title? I am just curious as to the way these two are working together.
Yes, this is what happens in -initWithRootViewController:
and others, the UINavigationController
iterates through all of the UIViewController
objects in the navigation stack and assigns the respective properties to itself.
Something like this is happening under the hood:
for(UIViewController *vc in viewControllers) {
[vc setNavigationController:self];
//set other properties here as well...
}
精彩评论