Reputation: 715
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?
Upvotes: 3
Views: 6475
Reputation: 502
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.
Upvotes: 1
Reputation: 76
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;
Upvotes: 0
Reputation: 498
If you have only one storyBoard in your project then you can also use simply
self.storyboard
Upvotes: 1
Reputation: 715
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];
Upvotes: 2