【问题标题】:How to install a NavigationController as the root view in a tab bar?如何在标签栏中安装 NavigationController 作为根视图?
【发布时间】:2011-05-04 07:29:14
【问题描述】:

如何在标签栏视图中安装 NavigationController 作为根视图?

在我的 applicaton:didFinishLaunchingWithOptions: 方法中我创建了一个标签栏界面,将窗口的 rootViewController 设置为 tabBarController。

现在,在我的一个标签栏视图中,我想在顶部添加一个导航栏。我怎样才能做到这一点?

我应该继承导航控制器吗?

谢谢

【问题讨论】:

  • 别忘了接受答案。

标签: iphone ios uinavigationcontroller uitabbarcontroller


【解决方案1】:

听起来你是在代码中做的,而不是 IB,所以这就是你可以做的。

// First create your RootViewController:
UIViewController *rootViewController = [[UIViewController alloc] init];
// Then add the rootViewController to a UINavigationController
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
// Now your RootViewController is a UINavigationController
// Add it to your UITabBarController
[tabBarController.viewControllers addObject:navigationController];
// You can now get rid of the RootViewController and UINavigationController
[rootViewController release];
[navigationController release];

【讨论】:

  • 谢谢!我正在尝试以编程方式与 IB 相比。非常感谢,这对您有很大帮助
  • 其实,现在如何让navigationCONtroller在标签被选中时显示出来?
  • 这应该会自动出现。 tabBarController 应该会为你处理好这个。
【解决方案2】:

您可以在界面生成器中执行此操作。将标签栏控制器内的视图控制器替换为导航控制器。然后将视图控制器(在导航控制器内部)的类和 Nib 名称设置为您的根类。

【讨论】:

    【解决方案3】:

    您必须首先创建一个 UITabbarController 应用程序,然后转到 MainWindow.xib 文件。默认情况下,将创建两个选项卡视图。

    检查标签栏的属性属性并将视图更改为RootViewController。您必须将类名和 xib 文件名设置为 RootViewController。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-03
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2012-10-09
      • 2012-03-25
      • 2011-08-24
      相关资源
      最近更新 更多