为什么选择tabbarController索引编程不会调用委托方法 [英] why does selecting a tabbarController index programatically doesnt call delegate method

查看:226
本文介绍了为什么选择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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆