2012-03-31 111 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方法。