Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does selecting a tabbarController index programatically doesnt call delegate method

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];

or

[self.tabBarController setSelectedViewController:[self.tabBarController.viewControllers objectAtIndex:0]];

the delegate methods are not called. What is the reason for that?

like image 513
yunas Avatar asked Mar 07 '13 18:03

yunas


1 Answers

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];
}
like image 130
user2142920 Avatar answered Oct 05 '22 16:10

user2142920