I did it mostly thru interface builder, which makes it difficult to show code, but here are the steps I did:
First, I started by creating a basic tab-bar project, without navigation controllers. This created my main nib file, with the tabs along the bottom of my main window and the views associated with each above.
Then, for the particular tabs where I wanted to show the associated view under a nav bar, I selected that tab button in Interface Builder, and in the inspector I then changed the Class Identity of the associated view for that tab from UIViewController to UINavigationController. That seemed to be the main trick.
I then selected the view itself (the view which appears under the nav controller, which in my case is a UITableView) and I changed its Class Identity from UITableViewController to my custom class which inherited from UITableViewController. I also specified that that view controller should be associated with a different nib file. That nib file simply had the table view that I wanted to show beneath the nav bar, with File's Owner being my custom UITableViewController-derived class.
The upshot is that when the user clicks that tab bar it creates a navigation controller. The navigation controller in turn then creates an instance of my custom UITableViewController-derived class and loads the second nib file containing that view. My custom class then accesses the navigation bar by means of code like this:
Code:
- (void)viewDidLoad {
[super viewDidLoad];
/* I wanted a segmented control to appear in the nav bar */
UISegmentedControl* ctl = [[UISegmentedControl alloc] initWithItems:[NSArray
arrayWithObjects:NSLocalizedString(@"all",@""),NSLocalizedString(@"restaurants",@""),NSLocalizedString(@"favorites",@""),nil]];
ctl.segmentedControlStyle = UISegmentedControlStyleBar;
[ctl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
ctl.selectedSegmentIndex = 0;
self.navigationItem.titleView = ctl ;
/* set the nav bar title */
self.title = NSLocalizedString(@"food_list","");
}