如何到达tabBar

时间:2011-05-08 09:27:04

标签: iphone objective-c xcode ipad

我有一个带标签栏的导航应用程序,第一个视图中有一个与第一个标签栏项目相关的Web视图。出现按钮Web视图,我想在触摸第一个标签栏项目时将其隐藏..请帮助thx

1 个答案:

答案 0 :(得分:2)

要获得控制器,只需:

[[tabBarController viewControllers] objectAtIndex:indexOfTheTab]

tabBarController指的是AppDelegate中的UITabBarController *tabBarController

编辑1:将其添加到AppDelegate.h

-(UITabBarController*)getTabBarController;

将此添加到您的AppDelegate.m

-(UITabBarController*)getTabBarController { return tabBarController; }

现在,您可以从任何地方访问它:

[(AppDelegate*)[[UIApplication sharedApplication] delegate] getTabBarController]

不要忘记#import "AppDelegate.h"

编辑2:在你AppDelegate.m

在第一种方法中,只需添加:self.tabBarController.delegate = self;

然后,覆盖:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    //something like : [tabBarController hideTheStuffs];
}

使用EDIT 2,您可以在标签栏中收听用户触摸,即使标签项已经是当前标签项。使用EDIT 1,您可以根据需要从任何地方访问您的代表。

编辑3:

您的ControllerView.h中是否有IBOutlet UIWebView *myWebView(具有显示Web视图的视图的那个)。 如果没有,请添加此插座,然后将其连接到界面构建器中的webview。

在控制器中,在.h和.m中添加方法:

-(void)hideTheWebView { myWebView.hidden = YES; }

由于此方法在接口(.h)中声明,您可以从AppDelegate调用它,方法tabBarController:didSelectViewController。