apple's UINavigation Controller Class Reference says that pushViewController:animated: method can't push the instance of tab bar controller onto the stack, and I've read the following article also: Tab bar controller inside a navigation controller, or sharing a navigation root view
But, it seems adding instance of UITabBarController onto navigation controller's stack works well for me. I'm using XCode 4.2 (beta, surely) + iOS 5 and made some sample code like the following:
- (void)viewDidLoad
{
[super viewDidLoad];
self.secondCtrl = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
self.secondCtrl.title = @"Second";
self.thirdCtrl = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil] autorelease];
self.thirdCtrl.title = @"Third";
self.tabCtrl = [[[UITabBarController alloc] init] autorelease];
self.tabCtrl.title = @"Tab!";
self.tabCtrl.viewControllers = [NSArray arrayWithObjects:self.secondCtrl, self.thirdCtrl, nil];
}
- (IBAction)goNext:(id)sender {
[self.navigationController pushViewController:self.tabCtrl animated:YES];
}
The above code snippet is the part of window's root view controller's source code.
I'm wondering apple's reference is out-of-dated or my code works oddly?
A UITabBarController inherits from UIViewController so by that, as your code shows, it is possible to push one onto a navigation stack, however Apple does not typically recommend it. From the Apple iOS Human Interface Guidelines:
Of course, there are always exceptions to the rule, so I would recommend that you use your best judgement and decide what is best for the user.