[英]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. 我正在使用xCode 5中的应用程序。这是第一次使用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.
成功登录后,我想以编程方式从此登录视图切换到我的标签栏控制器,标签索引设置为1。
I do not have a custom class for my UITabBarController. 我的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];
如果您的项目中只有一个storyBoard ,那么您也可以简单地使用
self.storyboard
The best way to do this is to set your rootviewController to tabBarcontroller as soon as you authenticate the user. 执行此操作的最佳方法是在对用户进行身份验证后立即将rootviewController设置为tabBarcontroller。 Here is how you can do this in swift.
以下是如何在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. TabBarController是标签栏控制器的故事板ID。 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.
将ViewControllers按钮( 或文件所有者连接方法 )中的segue拖动到TabBarVC。 Choose modal style and animation if you wish.
如果您愿意,可以选择模态样式和动画。
Add a new custom class for UITabBarController and assign it to TabBarVC in storyboard. 为UITabBarController添加一个新的自定义类,并将其分配给storyboard中的TabBarVC。 In it's implementation file;
在它的实现文件中; put self.selectedIndex = 1;
把self.selectedIndex = 1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.