Use the wizard to use the tab bar application and configure it as usual. On any tab where you want to add a navigation controller, create it in XIB using the library. My XIB has:
- File Owner DescriptiveNameNavViewController
- First Responder
- View UIVIew
- Navigation Controller UINavigationController
- Navigation Bar UINavigationBar
Please note that there is nothing in the view. See ViewDidLoad below for a UINavigationController connected to a UIView.
There is no specific standard in the header file for the Tab ViewController (which I call DescriptiveNameNavViewController here, but I use [Something] NavViewController to remind me that this ViewController contains a navigation controller with This is the name of the controller that I set in MainWindow.xib, created by the wizard.) Configure the UINavigationController * IBOutlet with the navigation controller in the XIB attached to it:
@interface DescriptiveNameNavViewController : UIViewController { UINavigationController *navigationController; } @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; @end
In the controller for DescriptiveNameNavViewController do something like this:
- (void)viewDidLoad { [super viewDidLoad]; [[self view] addSubview:[navigationController view]]; DescriptiveNameController *aController = [[[DescriptiveNameController alloc ] initWithNibName:@"DescriptiveNameController" bundle:nil ] autorelease]; aController.title = @"Descriptive Title";
Setting up a delegate in DescriptiveNameNavViewController is very important, because otherwise you will not get the methods that you expect in instances of DescriptiveNameViewController, and everything else that you push on the navigation controller stack.
In the DescriptiveNameNavViewController, we implement the UINavigationControllerDelegate methods as follows:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if ([viewController respondsToSelector:@selector(viewDidAppear:)]) { [viewController viewDidAppear:animated]; } }
And this will cause messages to propagate to controllers inside the UINavigationController, as you expect. It seems that many of the problems people face are related to the fact that viewDidAppear: or other methods are not called in the ViewControllers pushed into the NavigationController.
In any case, let me know if more details help.