I have a tab bar that I am trying to detect if it was touched inside view controller 2

允我心安 提交于 2019-12-24 17:46:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!