How to trigger method “tabBarController:didSelectV

2019-02-17 09:59发布

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?

2条回答
欢心
2楼-- · 2019-02-17 10:21

For swift 3.0 you can programmatically call tabbar delegate method like this

self.tabController.selectedIndex = index (e.g. 0,1...etc)
self.tabController.delegate.tabBarController(self.tabController, didSelectViewController: self.tabController.viewControllers[index])
查看更多
放我归山
3楼-- · 2019-02-17 10:30
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
查看更多
登录 后发表回答