iPhone应用程序-检测按下了哪个选项卡栏项目 [英] iphone app - detect which tab bar item was pressed
问题描述
我有一个基于选项卡栏的应用程序,其中有5个以上的选项卡栏项目-因此,我可以在视图中直接显示其中的4个项目,其余的则可以通过选择更多"选项卡来获得.按下选项卡栏项时,我想检测出它是哪个项.
因此,在
- (void)tabBarController:(UITabBarController *)tabBarCtrl didSelectViewController:(UIViewController *)viewController
方法,我使用tabBarCtrl.selectedViewController.title
来获取项目的标题.
i have a tab bar based application, with more than 5 tab bar items - so i get 4 of them directly showing in the view and the rest available by selecting the "More" tab. When a tab bar item is pressed, i want to detect which one was it.
So, in the
- (void)tabBarController:(UITabBarController *)tabBarCtrl didSelectViewController:(UIViewController *)viewController
method, i use tabBarCtrl.selectedViewController.title
to get the item's title.
这适用于视图中可见的选项卡-即第4个和更多"选项卡-但不适用于按更多"选项卡后显示在列表中的其余选项卡栏项目
This works for the tabs visible in the view -that is the 4 first and the "More" tab- but does not work for the rest of my tab bar items which are shown in the list after pressing the "More" tab.
我可以看到,从更多"列表中选择一个选项卡时,甚至没有调用didSelectViewController方法.
按下时如何检测其中的任何一个?
I can see that the didSelectViewController method is not even called when selecting a tab from the "More" list.
How can i detect any of them when pressed?
谢谢.
推荐答案
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
NSLog(@"controller class: %@", NSStringFromClass([viewController class]));
NSLog(@"controller title: %@", viewController.title);
if (viewController == tabBarController.moreNavigationController)
{
tabBarController.moreNavigationController.delegate = self;
}
}
这篇关于iPhone应用程序-检测按下了哪个选项卡栏项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!