私は3つのタブバーアプリケーションを持っており、私のタブはTAB1、TAB2、TAB3です。TAB1ビューコントローラーに次のコードを記述して、ユーザーが押したタブを検出しました
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSLog(@"tab selected: %@", item.title);
}
しかし、このデリゲートは呼び出されません
私は自分のタブを appdelegate.m にセットアップしました
- (void)setupTabBar
{
self.myWorkListViewController = [[MyWorkListViewController alloc] initWithNibName:@"MyWorkListViewController"
bundle:nil];
self.askHRViewController = [[AskHRViewController alloc] initWithNibName:@"AskHRViewController"
bundle:nil];
self.moreViewController = [[MoreViewController alloc] initWithNibName:@"MoreViewController"
bundle:nil];
self.bookLeaveViewController = [[BookLeaveViewController alloc] initWithNibName:@"BookLeaveViewController"
bundle:nil];
self.helpViewController = [[HelpViewController alloc] initWithNibName:@"HelpViewController"
bundle:nil];
// Create navigation controllers
workListNavigationController = [[UINavigationController alloc] initWithRootViewController:self.myWorkListViewController];
askHRNavigationController = [[UINavigationController alloc] initWithRootViewController:self.askHRViewController];
bookLeaveViewController = [[UINavigationController alloc] initWithRootViewController:self.bookLeaveViewController];
moreNavigationController = [[UINavigationController alloc] initWithRootViewController:self.moreViewController];
helpNavigationController = [[UINavigationController alloc] initWithRootViewController:self.helpViewController];
[self setTabBarImagesAndText];
// Setup tab bar controller
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:workListNavigationController, askHRNavigationController, bookLeaveViewController, helpNavigationController,moreNavigationController, nil]];
//Set TabBar background
[self.tabBarController.tabBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TabBar_iOS4_Background"]] atIndex:0];
[self.tabBarController setSelectedIndex:0];
}