如何在ViewController之后启动TabBarController

时间:2016-08-23 07:24:28

标签: ios objective-c uitabbarcontroller

我有一个loginViewController,并且在成功登录后,我想通过显示具有父标签栏的主屏幕来启动应用程序。enter image description here

我目前正在使用的流程是:

UITabBarController *arvc = [self.storyboard instantiateViewControllerWithIdentifier:@"homeVC"];

    [self presentViewController:arvc animated:YES completion:nil];

但是它没有加载屏幕下方的标签栏。那么如何实现它。

3 个答案:

答案 0 :(得分:1)

storyboard,从您的loginviewController ctrl+dragUITabbarController,然后从show中选择popup。它将从您的登录视图控制器创建新的show segue到tabbarcontroller。然后点击segue,然后从attribute inspector设置identifier pushToTabbarController或者您要保留的任何标识符,选择 [self performSegueWithIdentifier:@"pushToTabbarController" sender:nil]; //identifier that you have set in Interface builder

现在当你成功登录并想要去tabbbarviewcontroller时,你只需要打电话,

UserId

答案 1 :(得分:0)

   MyViewController* vc1 = [[MyViewController alloc] init];
   MyOtherViewController* vc2 = [[MyOtherViewController alloc] init];

   NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
   tabBarController.viewControllers = controllers;
    window.rootViewController = tabBarController;

答案 2 :(得分:0)

使用以下代码成功登录后,您可以浏览应用程序。方法presentViewController将更新viewcontrollers的hirachary,当前viewController将变为rootViewController ..

您必须在故事板上使用identitytabBarController Identity Inspector提供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]; ,请参阅图片。

enter image description here

A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll