I have a storyboard which has following views (scenes):
Based on user login by clicking on the button (Sign in), I programatically load tab bar controller with always first tab with following code:
LibraryWebViewContoller *lbc = [self.storyboard instantiateViewControllerWithIdentifier:@"docovaMainTabBarController"];
[self presentViewController:lbc animated:YES completion:nil];
What I want do is be able to open different tabs programmatically with TabBarController from storyboard. So far I am able to open the tab bar controller with first tab but no luck in opening others as it always seem to load the TabBarController with first tab selected.
I was able to solve the issue by using following code:
UITabBarController *tbc = [self.storyboard instantiateViewControllerWithIdentifier:@"docovaMainTabBarController"];
tbc.selectedIndex=1;
[self presentViewController:tbc animated:YES completion:nil];
Also, remember to edit the storyboard and give the UITabBarController a storyboard ID set to docovaMainTabBarController so it can be uniquely identified within the storyboard.
let tbc = self.storyboard.instantiateViewController(withIdentifier:"docovaMainTabBarController") as! UITabBarController
tbc.selectedIndex = 1
self.present(tbc, animated: true, completion:nil)
Say you wanted to have the second view controller selected. Set the activeViewController property on the tab bar controller)
lbc.activeViewController = [lbv.viewControllers objectAtIndex:1];
(not sure of lbc is the tab bar controller or the first view controller in the tab bar - assuming it is)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With