获取tabBar触摸的索引
问题描述:
我如何获取tabBar的索引当我触摸选项卡?获取tabBar触摸的索引
从来就延长我的同班同学<的UITabBarController>和添加的方法
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
if (viewController == tabBarController.moreNavigationController)
{
tabBarController.moreNavigationController.delegate = self;
}
}
但是,当我触摸标签物品,其方法isn't触发。 我该怎么办?
答
UITabBarController有一个属性selectedIndex
,您可以使用它来查找选定的选项卡。有关的UITabBarController
的更多信息,可以发现here
此外,一定要设置你的UITabBarController的delegate
财产,否则委托的消息(如didSelectViewController:
)将不被接收。
答
您是否在创建代理类时将UITabBarController
的代表设置为您的委托类?
您是否设置了委托属性? – Chakalaka 2012-02-07 17:43:49
我没有创建UITabBarController对象,所以这一定是问题所在。但就像我不会创建它,我会使用FelixLam答案来解决我的问题,但它可能不工作的原因是edc1291给出的原因。 – bruno 2012-02-07 17:50:05
你甚至可以在你的interfaceBuilder中设置委托 – Chakalaka 2012-02-07 17:57:40