导航控制器中的选项卡栏控制器可以工作,但是参考资料说不会 [英] tab bar controller in navigation controller does work, however reference says it won't

查看:48
本文介绍了导航控制器中的选项卡栏控制器可以工作,但是参考资料说不会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

苹果的UINavigation控制器类参考表示pushViewController:animated:方法无法将选项卡栏控制器的实例推入堆栈,并且我还阅读了以下文章:

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

但是,似乎将UITabBarController的实例添加到导航控制器的堆栈中对我来说效果很好.我正在使用XCode 4.2(肯定是beta版)+ iOS 5,并编写了一些示例代码,如下所示:

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?

推荐答案

一个UITabBarController继承自UIViewController,因此,如您的代码所示,可以将其推入导航堆栈中,但是Apple通常不推荐这样做.从Apple iOS人机界面指南:

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.

这篇关于导航控制器中的选项卡栏控制器可以工作,但是参考资料说不会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆