I would like to be able to programatically select a tab on a UITabBarController and then access the view that is loaded in order to set the segment loaded by default.
For example if I have a menu and click a button titled 'A/B', I want it to select the 'A' tab, and then the 'B' segment. If I click a button titled 'A/C', I want it to select the 'A' tab and then the 'C' segment.
The first part of the problem I have managed to figure out as follows:
class TabBarController: UITabBarController {
...
func selectTab(name: String) {
for tab in self.viewControllers! {
if(name == tab.tabBarItem.title) {
self.selectedViewController = tab
return
}
}
}
}
I'm not sure how to get the view that is automatically opened though. What is the best way to do this?
Many thanks in advance!