我从之前的问题中得到了一些建议,并对代码进行了相当多的修改。我仍在尝试检测何时触摸标签栏项目。如果所选索引为零,则应在nslog中返回“moo”。可能会遗漏一个小细节。
查看控制器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.h
@interface viewcontroller2 : UIViewController<UIWebViewDelegate,UITabBarControllerDelegate>{
}
查看控制器2
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
if(self.tabBarController.selectedIndex == 0){
NSLog(@"MOO");
return(TRUE);
}
return(FALSE);
}
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
}
答案 0 :(得分:0)
将您的代表设置为自己:
[tabBarViewControllers setDelegate:self];
答案 1 :(得分:0)
只需在appdelegare(你正在创建的地方)实现你的tabBar委托
self.objTabBarController.delegate=self;
在appdelegate中实现其委托方法
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
NSLog(@"MOO");
return YES;
}