Switch from View Controller to Tab Bar Controller in a Storyboard xCode
I am working on an app in xCode 5. This is a first at using the Storyboard. My app starts with a simple username/password login screen. Upon successful login, I want to programmatically switch from this login View to my Tab Bar Controller with the tab index set at 1.
I do not have a custom class for my UITabBarController. I can build one if need be. Can someone help get me started or point me in the right direction?
Funny how typing out the question can help you solve it. Here is the code I used in case someone has the same issue in the future
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; UITabBarController *vc = (UITabBarController *)[storyboard instantiateViewControllerWithIdentifier:@"UITabBarController"]; [self presentViewController:vc animated:YES completion:nil]; [vc release];
If you have only one storyBoard in your project then you can also use simply
The best way to do this is to set your rootviewController to tabBarcontroller as soon as you authenticate the user. Here is how you can do this in swift.
let tabBarController = self.storyboard?.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate appDelegate.window?.rootViewController = tabBarController
Where TabBarController is the storyboard id of your tab bar controller. It could be anything whatever name you have given it.
In storyboard; drag a segue from your ViewControllers button (or File's Owner to connect a method) to your TabBarVC. Choose modal style and animation if you wish.
Add a new custom class for UITabBarController and assign it to TabBarVC in storyboard. In it's implementation file; put self.selectedIndex = 1;