tab bar controller in navigation controller does w

2019-09-02 22:26发布

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?

1条回答
We Are One
2楼-- · 2019-09-02 22:40

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:

In general, use a tab bar to organize information at the application level. A tab bar is well-suited for use in the main app view because it’s a good way to flatten your information hierarchy and provide access to several peer information categories or modes at one time.

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.

查看更多
登录 后发表回答