views:

155

answers:

1

If you have a UINavigationController's UIViewController present a UITableViewController (TVC) modally, is there a way for the TVC to display the UINavigationBar of its parentViewController? Or, should I have it create a new UINavigationBar, item, buttons, etc. for the modal TVC?

A: 

I would just instantiate a UINavigationController right before you present your modal.

YourViewController *modalViewController = [[YourViewController alloc] initWithNibName:@"foo" bundle:nil]
UINavigationController *tmpNavController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
[modalViewController release];
[self.navigationController presentModalViewController:tmpNavController animated:YES];
[tmpNavController release];

This is just back-of-the-envelope - I wouldn't copy and paste that code w/o a double-check!

phooze
Yeah, but can't I use the one that already exists?
MattDiPasquale
No, because you're presenting modally. Think of the "modal" as a "brand new world" in terms of views. You need to start all over again and recreate a new navigation controller for your new, modal world.Then, when you're ready to go back to your old view hierarchy, you call [self dismissModalViewControllerAnimated:YES]
phooze
Are you sure? There's gotta be a way to programmatically access the NavigationBar of the NavigationController I made via the parentViewController and add it as a subview to the current modal view. For now, I will just create another UINavigationBar, and a UINavigationItem, and a UIBarButtonItem as the leftBarButtonItem of the UINavigationItem, and then push the UINavigationItem onto the UINavigationBar, which I'll then add as a subview to the modal view. I don't need the navigationController. See: http://github.com/acani/acani-chat/blob/master/Lovers/Classes/ProfileViewController.m
MattDiPasquale