【问题标题】:iOS app with tabbar and navigation controller带有标签栏和导航控制器的 iOS 应用
【发布时间】:2012-05-12 22:11:22
【问题描述】:

在创建我的第一个 iPhone 应用程序的过程中,我注意到来自 Apple 的示例要么有标签栏,要么有导航栏,但从来没有两者兼有。

可以这样做吗?

所以我这里有一个带有 3 个按钮的标签栏,我现在如何将导航控制器添加到我的整个应用程序中?

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

UIViewController *activityViewController = [[[ActivityViewController alloc] initWithNibName:@"ActivityViewController" bundle:nil] autorelease];
UIViewController *agendaViewController = [[[AgendaViewController alloc] initWithNibName:@"AgendaViewController" bundle:nil] autorelease];
UIViewController *settingsViewController = [[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil] autorelease];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:activityViewController, agendaViewController, settingsViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

编辑:

我真的没有关注,所以在我的 appdelegate 中我创建了一个 navigationController 并将其用作 rootViewController。

然后我创建了一个 tabBarController 并将其添加到我的窗口中

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

UINavigationController *mainViewController = [[UINavigationController alloc] init];
self.mainViewController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];

self.window.rootViewController.title = @"test";

MainViewController *tabBarController = [[MainViewController alloc] init];
[self.window addSubview:tabBarController.view];

但是每当我运行时,我都会收到错误“

不支持推送导航控制器

我还是错过了什么吗?

【问题讨论】:

    标签: ios navigation tabbar


    【解决方案1】:

    嘿,这个概念很简单:

    你的 rootViewController 必须是你的 navigationController,因为它来回推动你的视图。

    YourRootController *cont = [[YourRootController alloc] init];
    
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:cont];
    

    其中YourViewControllerUITabBarController 的子类

    就是这样。

    【讨论】:

      【解决方案2】:

      您可以创建一个导航控制器,然后创建一个 tabBarController 并将您的导航控制器添加到它使用

       //incase you have 2 navigation controllers
       tabBarController.viewControllers=[NSArray arrayWithObjects:navigationController1, navigationController2, nil ];
      

      【讨论】:

      • 他想要一个用于整个应用程序的 navigationController。所以它必须是根
      • 如果他按照我在 AppDelegate.m 中的描述初始化标签栏控制器,然后 self.window.rootController=tabBarController;它会工作的。
      猜你喜欢
      • 2017-05-14
      • 1970-01-01
      • 2016-11-08
      • 2015-05-03
      • 2010-09-27
      • 2019-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多