UINavigationController和UITabbarController难题

时间:2011-06-06 09:40:08

标签: iphone uinavigationcontroller uitabbarcontroller uitabbaritem

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

我的 main.xib 一个 TabBarController ,设置了五个 viewControllers

我试图让第一个viewcontroller成为一个导航控制器,这样如果第一个选项卡被选中,我可以将视图推送到视图中。

但是对于我的生活,我无法让它发挥作用?

我在我的app delegate 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];

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

请小心吗? thnx

4 个答案:

答案 0 :(得分: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];

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

希望他对你有所帮助。

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

答案 1 :(得分:1)

您的 tabBarController 只包含一个 viewController 。因此 tabBarController 中只有一个 tabBarItem 可用。由于只有一个 viewController 可用,默认情况下将选择 tabBarItem ,您无法更改选择。所以你不觉得有一个按钮。但它在那里。您可以为 viewController 设置标题图像,您将看到差异。

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

答案 2 :(得分:0)

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

希望它可以帮助你......

答案 3 :(得分:0)

[first.tabBarItem initWithTitle:@"First" image:[UIImage imageNamed:@"first.png"] tag:0];