Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger method "tabBarController:didSelectViewController:" programmatically?

Currently, I am trying to trigger the 'didSelectViewController' method programmatically via the following code:

self.tabController.selectedViewController 
        = [self.tabController.viewControllers objectAtIndex:NEWSTAB_INDEX];

However, the 'didSelectViewController' method wasn't called. How can I trigger the method without having to manually select the tab bar?

like image 1000
Zhen Avatar asked Sep 17 '11 08:09

Zhen


1 Answers

self.tabController.selectedIndex = NEWSTAB_INDEX;   // to actually switch to the controller (your code would work as well) - not sure if this does or not send the didSelectViewController: message to the delegate
[self.tabController.delegate tabBarController:self.tabController didSelectViewController:[self.tabController.viewControllers objectAtIndex:NEWSTAB_INDEX]];  // send didSelectViewController to the tabBarController delegate
like image 90
alex-i Avatar answered Nov 03 '22 01:11

alex-i