2012-03-31 112 views
2

目前我有一個UITabBarController,其上有4個項目,都有關聯的視圖控制器。我想添加第5個標籤欄項目,該項目不會轉到新的視圖控制器,而是在Safari中啓動網站。基本上,它就像一個UIButton。從UITabBarController打開網站

那麼結果會是:

用戶在選項卡1.
用戶點擊選項卡上的5(5片變成藍色瞬間)。
視圖不變。
網站在Safari中打開(我知道如何做到這一點的一部分)
當用戶返回到應用程序,他們仍然在標籤1(選項卡1是藍色的)

任何想法?

目前我的UITabBarController是這樣設置(其中localControllerArray是4個UINavigationControllers數組):

tabBarController.viewControllers = localControllersArray; 
[localControllersArray release];  
[self.window setRootViewController:tabBarController]; 
[tabBarController release]; 

回答

2

你知道如何UITTabBarController具有代表性質?創建一個實現UITabBarControllerDelegate協議的對象,並將其設置爲委託。然後,當您選擇任何選項卡時,代表的tabBarController:didSelectViewController:將被調用。在它中你可以檢查你的第5個標籤是否被竊聽。在這種情況下,只需將tabbarcontroller的selectedIndex屬性設置爲你想要的。而已。

PS,其實你應該只需撥打tabBarController:shouldSelectViewController: 而不是這種方式,視圖不會切換。

+0

工程就像一個魅力。謝謝。 – Joel 2012-03-31 04:25:48

0
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController; 
switch(mytabbar.selectedIndex) 
{ 
case 0: 
    [imageView1 setImage:[UIImage imageNamed:@"Tab1_sel.png"]]; 
    [imageView2 setImage:[UIImage imageNamed:@"Tab2.png"]]; 
    [imageView3 setImage:[UIImage imageNamed:@"Tab3.png"]]; 
    [imageView4 setImage:[UIImage imageNamed:@"Tab4.png"]]; 
    [imageView5 setImage:[UIImage imageNamed:@"Tab5.png"]]; 
    break; 

case 1: 

它爲我工作嘗試它...把它放在appdelegate方法。