为什么选择tabbarController索引编程不会调用委托方法 [英] why does selecting a tabbarController index programatically doesnt call delegate method
本文介绍了为什么选择tabbarController索引编程不会调用委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我们触摸tabbarcontroller的tabbaritem时,调用委托方法:
when we touch the tabbaritem of the tabbarcontroller the delegate methods are called:
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
但是当尝试以编程方式执行相同的操作时,即
but when try to do the same thing programmatically, i.e.
[self.tabbarController setSelectedIndex:selectedIndexNo];
或
[self.tabBarController setSelectedViewController:[self.tabBarController.viewControllers objectAtIndex:0]];
这是什么原因?
推荐答案
覆盖UITabBarController setSelectedIndex:
override UITabBarController setSelectedIndex:
-(void)setSelectedIndex:(NSUInteger)selectedIndex
{
//must call super function.
[super setSelectedIndex:selectedIndex];
[self myMethod];
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
[self myMethod];
}
这篇关于为什么选择tabbarController索引编程不会调用委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文