0

I took some advice from the previous questions and modify the code quite a bit.I am still trying to detect when a tab bar item is being touched.If the selected index is zero is should return "moo" in nslog.I might be missing a minor detail.

view controller 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];

view controller 2.h

     @interface viewcontroller2 : UIViewController<UIWebViewDelegate,UITabBarControllerDelegate>{

       }

view controller 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;
   }
4

2 回答 2

0

将您的委托设置为自我:

[tabBarViewControllers setDelegate:self];
于 2013-03-19T17:26:15.543 回答
0

只需在 appdelegare(您正在创建的地方)中实现您的 tabBar 委托

self.objTabBarController.delegate=self;

并在 appdelegate 中实现其委托方法

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    NSLog(@"MOO");
    return YES;
}
于 2013-03-19T17:27:10.550 回答