[英]Xcode Storyboard Tabbed application (UITabBarController) - tell when tab selected
Using Xcode 6 I have created an Tabbed Application using a storyboard with the supplied template. 使用Xcode 6,我使用带有提供的模板的情节提要创建了一个选项卡式应用程序。
I need a function to fire when the third tab of the UITabBarController is selected. 当选择UITabBarController的第三个选项卡时,我需要一个函数来触发。
I can't use the ViewDidLoad as I need it fire every time the view is accessed by clicking on the tab (not just the first time( and I can't use ViewWillAppear as I need specific behaviour when view is accessed via the tab as opposed to segued back to from subsequent (modal) view controllers. 我不能使用ViewDidLoad,因为每次需要通过单击选项卡访问视图时都会触发ViewDidLoad(不仅仅是第一次(并且我不能使用ViewWillAppear,因为当通过选项卡访问视图时我需要特定的行为)反对与后续(模态)视图控制器隔离。
Any advice would be appreciated. 任何意见,将不胜感激。 Many thanks in advance.
提前谢谢了。
Implement this delegate method of UITabBarControllerDelegate on some UIViewController class 在某些UIViewController类上实现UITabBarControllerDelegate的委托方法
- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController {
NSUInteger indexOfTab = [theTabBarController.viewControllers indexOfObject:viewController];
// Your code here
}
OR 要么
You can subclass UITabBarController and override the following method. 您可以继承UITabBarController的子类,并重写以下方法。
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSUInteger indexOfTab = [[theTabBar items] indexOfObject:item];
// Your code here}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.