0

我已搜索和搜索,但仍然無法找出這個問題! :-(UINavigation Controller和UITabbarController connumdrum

我在main.xib一個TabBarController是設置有五個viewControllers

我想獲得第一的ViewController是一個導航控制器,這樣如果第一個選項卡中選擇我可以推及彈出意見眼簾

但對我的生活,我不能得到這個工作

我在我的應用程序委託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

回答

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]; 

這樣,您必須將其餘視圖控制器添加到您的tabbar控制器。

希望它對你有幫助。

如有任何困難,請告知我。

+0

茶青!感謝芽;-)感謝所有誰迴應,感謝它;-) – user7865437 2011-06-06 12:47:01

0

下面是解釋鏈接如何設置的TabBar控制器和導航控制器
Link 1

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

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

您的tabBarController只包含一個viewController。所以在tabBarController中只會有一個tabBarItem。由於只有一個viewController可用,所以tabBarItem將被默認選中,並且您無法更改選擇。所以你不覺得有一個按鈕。但它在那裏。您可以設置標題圖片viewController您將看到區別。

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