How to call the method "tabBarController: didSelectViewController:" programmatically?

I'm currently trying to run the 'didSelectViewController' method programmatically through the following code:

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

However, the 'didSelectViewController' method was not called. How can I call a method without having to manually select the tab bar?

+6
source share
2 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 
+16
source

For quick 3.0, you can programmatically call the tabbar delegate method like this

 self.tabController.selectedIndex = index (eg 0,1...etc) self.tabController.delegate.tabBarController(self.tabController, didSelectViewController: self.tabController.viewControllers[index]) 
0
source

Source: https://habr.com/ru/post/897517/


All Articles