【问题标题】:UINavigation Controller and UITabbarController connumdrumUINavigationController 和 UITabbarController 难题
【发布时间】:2011-06-06 09:40:08
【问题描述】:

我已经搜索和搜索,但仍然无法解决这个问题! :-(

我的 main.xib 中有一个 TabBarController,它由五个 viewControllers 设置。

我正在尝试让第一个视图控制器成为导航控制器,这样如果选择了第一个选项卡,我就可以将视图推送和弹出视图。

但是对于我的生活,我无法让它工作?

我在我的应用委托 didLaunch 方法中尝试了这个:

UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
FirstViewController *first = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:[NSBundle mainBundle]];
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:first];  
NSArray* controllers = [NSArray arrayWithObjects:firstNav, nil];  
tabBarController.viewControllers = controllers;  
[window addSubview:tabBarController.view];

我看到我的视图显示但标签栏上没有按钮?

请给点小费??谢谢

【问题讨论】:

    标签: iphone uinavigationcontroller uitabbarcontroller uitabbaritem


    【解决方案1】:

    为此,您必须以编程方式在 TabBar 中添加视图控制器。如下:

    oFirstViewController.title = @"First View";
    oFirstViewController.tabBarItem.image = [UIImage imageNamed:@"ico.png"];
    UINavigationController *myNavigationController1 = [[UINavigationController alloc] initWithRootViewController:oFirstViewController]; 
    tabBarController.viewControllers = [NSArray arrayWithObjects:myNavigationController1, myNavigationController2, myNavigationController3, myNavigationController4, nil];
    

    这样,您必须将剩余的视图控制器添加到您的标签栏控制器。

    希望对你有帮助。

    如有任何困难,请告诉我。

    【讨论】:

    • 恰恰!谢谢 bud ;-) 也感谢所有回复的人,感激不尽 ;-)
    【解决方案2】:

    您的tabBarController 只包含一个viewController。因此,tabBarController 中将只有一个 tabBarItem 可用。由于只有一个 viewController 可用,默认情况下会选择该 tabBarItem 并且您无法更改选择。所以你不会觉得有一个按钮。但它在那里。您可以为 viewController 设置 titleimage,您将看到不同之处。

    first.title = @"firstTab";
    first.navigationItem.image = [UIImage imageNamed:@"firstTab.png"];
    

    【讨论】:

      【解决方案3】:

      下面是解释如何设置标签栏控制器和导航控制器的链接
      Link 1

      希望对你有帮助......

      【讨论】:

        【解决方案4】:
        [first.tabBarItem initWithTitle:@"First" image:[UIImage imageNamed:@"first.png"] tag:0]; 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-11-28
          • 2010-11-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多