如何在 ViewController 之后启动 TabBarController
How to start the TabBarController after a ViewController
我有一个 loginViewController 并且在成功登录后我想通过显示具有父选项卡栏的主屏幕来启动应用程序。
我目前使用的流程是:
UITabBarController *arvc = [self.storyboard instantiateViewControllerWithIdentifier:@"homeVC"];
[self presentViewController:arvc animated:YES completion:nil];
但它不会加载屏幕下方的标签栏。那么如何实现呢。
MyViewController* vc1 = [[MyViewController alloc] init];
MyOtherViewController* vc2 = [[MyOtherViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
tabBarController.viewControllers = controllers;
window.rootViewController = tabBarController;
在您的 storyboard
中,从您的 loginviewController ctrl+drag
到您的 UITabbarController
和 select show
从 popup
。它将创建从您的登录视图控制器到 tabbarcontroller 的新 show
segue。然后 select segue
点击它并从 attribute inspector
设置它 identifier
就像 pushToTabbarController
或任何你想保留的标识符。
现在当你成功登录,想去tabbbarviewcontroller时,你只需要调用,
[self performSegueWithIdentifier:@"pushToTabbarController" sender:nil]; //identifier that you have set in Interface builder
您可以在成功登录后使用以下代码导航您的应用程序。方法 presentViewController
将更新 viewcontrollers
的层次结构,当前 viewController
将变为 rootViewController
..
您必须在故事板上使用 Identity Inspector
将 identity
分配给您的 tabBarController
参见图片。
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"viewControllerName"];
// this will update viewcontroller stack and vc will become top viewController
[self presentViewController:vc animated:NO completion:nil];
我有一个 loginViewController 并且在成功登录后我想通过显示具有父选项卡栏的主屏幕来启动应用程序。
我目前使用的流程是:
UITabBarController *arvc = [self.storyboard instantiateViewControllerWithIdentifier:@"homeVC"];
[self presentViewController:arvc animated:YES completion:nil];
但它不会加载屏幕下方的标签栏。那么如何实现呢。
MyViewController* vc1 = [[MyViewController alloc] init];
MyOtherViewController* vc2 = [[MyOtherViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
tabBarController.viewControllers = controllers;
window.rootViewController = tabBarController;
在您的 storyboard
中,从您的 loginviewController ctrl+drag
到您的 UITabbarController
和 select show
从 popup
。它将创建从您的登录视图控制器到 tabbarcontroller 的新 show
segue。然后 select segue
点击它并从 attribute inspector
设置它 identifier
就像 pushToTabbarController
或任何你想保留的标识符。
现在当你成功登录,想去tabbbarviewcontroller时,你只需要调用,
[self performSegueWithIdentifier:@"pushToTabbarController" sender:nil]; //identifier that you have set in Interface builder
您可以在成功登录后使用以下代码导航您的应用程序。方法 presentViewController
将更新 viewcontrollers
的层次结构,当前 viewController
将变为 rootViewController
..
您必须在故事板上使用 Identity Inspector
将 identity
分配给您的 tabBarController
参见图片。
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"viewControllerName"];
// this will update viewcontroller stack and vc will become top viewController
[self presentViewController:vc animated:NO completion:nil];