在 Storyboard xCode 中从视图控制器切换到标签栏控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20462218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Switch from View Controller to Tab Bar Controller in a Storyboard xCode
提问by tomjung
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.
我正在 xCode 5 中开发一个应用程序。这是第一次使用 Storyboard。我的应用程序从一个简单的用户名/密码登录屏幕开始。成功登录后,我想以编程方式从这个登录视图切换到我的标签栏控制器,标签索引设置为 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?
我的 UITabBarController 没有自定义类。如果需要,我可以建一个。有人可以帮助我入门或为我指明正确的方向吗?
回答by tomjung
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];
回答by Atif Alvi
If you have only one storyBoardin your project then you can also use simply
如果您的项目中只有一个storyBoard,那么您也可以简单地使用
self.storyboard
回答by adubey
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.
最好的方法是在对用户进行身份验证后立即将 rootviewController 设置为 tabBarcontroller。这是您可以快速执行此操作的方法。
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.
其中 TabBarController 是标签栏控制器的故事板 ID。它可以是任何你给它起的名字。
回答by billgert
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.
在故事板中;将一个 segue 从您的 ViewControllers 按钮(或文件的所有者以连接方法)拖到您的 TabBarVC。如果您愿意,可以选择模态样式和动画。
Add a new custom class for UITabBarController and assign it to TabBarVC in storyboard. In it's implementation file; put self.selectedIndex = 1;
为 UITabBarController 添加一个新的自定义类并将其分配给故事板中的 TabBarVC。在它的实现文件中;把self.selectedIndex = 1;