问题
Basically I have a tab bar in view controller one. I am trying to detect if this tabaritem is touched inside view controller 2. What is the best method to perform such a task? I can post more specific code if you would like.
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
回答1:
You should use UITabBarControllerDelegate. See: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html
More specifically, look at
tabBarController:didSelectViewController:
"Tells the delegate that the user selected an item in the tab bar."
回答2:
Use delegate didselectviewcontroller and put delegate of tabbarcobtroller to self
来源:https://stackoverflow.com/questions/15504349/i-have-a-tab-bar-that-i-am-trying-to-detect-if-it-was-touched-inside-view-contro