简体   繁体   English

在Storyboard xCode中从View Controller切换到Tab Bar Controller

[英]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.

相关问题 查看标签栏 controller 从 storyboard swift 5 - view tab bar controller from storyboard swift 5 故事板-从模态视图控制器返回到选项卡栏控制器 - Storyboard - go back to tab bar controller from modal view controller 如何在不同故事板的标签栏上显示拆分视图控制器? - How to show split view controller on tab bar from different storyboard? 故事板使用segue将数据从视图控制器传递到标签栏 - Storyboard pass data from view controller to tab bar with segue iOS:使用情节提要的标签栏视图控制器 - iOS: tab bar view controller using storyboard Xcode中选项卡栏控制器视图的第一个视图 - The first view of the tab bar controller views in xcode 快速的Xcode从导航控制器切换到标签栏控制器的正确方法 - swift xcode proper way to switch from navigation controller to tab bar controller 使用故事板中的选项卡控制器以编程方式打开视图 - Open a view programmatically with tab controller from storyboard 从视图控制器移动到标签栏控制器 - Move from view controller to tab bar controller 是否可以将标签栏控制器类中从 Firebase 检索到的数据从标签栏控制器传输到视图控制器? Xcode,斯威夫特 - Is it possible to transfer data retrieved from Firebase in the tab bar controller class from the tab bar controller to a view controller? Xcode, Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM