我有一个标签栏,我试图检测它是否被触摸视图控制器2内

基本上我在视图控制器之一有一个标签栏。 我试图检测这个tabaritem是否触摸视图控制器2内。什么是执行这样的任务的最佳方法是什么? 如果你愿意,我可以发表更多具体的代码。

视图控制器1

TUHomeViewController *homeViewController = [[TUHomeViewController alloc] initWithNibName:nil bundle:nil]; UINavigationController *homeNavigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController]; homeNavigationController.tabBarItem = [[DSTabBarItem alloc] initWithFinishedSelectedImage:[UIImage imageNamed:@"home"] finishedUnselectedImage:[UIImage imageNamed:@"home1"] iconSize:CGSizeMake(76, 59) tag:0]; [tabBarViewControllers addObject:homeNavigationController]; 

视图控制器2

你应该使用UITabBarControllerDelegate。 请参阅: http : //developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html

更具体地说,看看

 tabBarController:didSelectViewController: 

“告诉代表用户在标签栏中select了一个项目。”

使用委托didselectviewcontroller并把tabbarcobtroller委托给自己