【问题标题】:Going from viewcontroller to tabbar's view programmatically以编程方式从 viewcontroller 到 tabbar 的视图
【发布时间】:2014-11-06 15:13:34
【问题描述】:

嗨,这是我的故事板,我想从 First view controller 转到 LoggedinViewController。

我正常使用

[self performSegueWithIdentifier:@"s1" sender:self];

但是如果我添加标签栏控制器这条线不起作用,我该如何解决这个问题?

【问题讨论】:

    标签: ios objective-c uitabbarcontroller tabbar


    【解决方案1】:

    如果您已嵌入导航控制器,则可以使用以下内容。

    UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:@"Story_Board_Name" bundle:nil];
     UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:@"TABid"];
    self.tabBarController.selectedIndex = 0;
     [self.navigationController pushViewController:self.tabBarController animated:YES];
    

    或者试试这个

    UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:@"Story_Board_Name" bundle:nil];
     UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:@"TABid"];
    self.tabBarController.selectedIndex = 0;
    [self performSegueWithIdentifier:@"s1" sender:self];
    

    【讨论】:

    • 如果LogedInViewController 嵌入了UINavigationController 怎么办?在这种情况下,上层代码不起作用。在我使用此代码的场景中,它会将我带到UITabbarController,但无法通过按下它们转到其他选项卡。它看起来冻结。对我来说有什么解决方案?谢谢
    【解决方案2】:

    给你的 tabbarcontroller 一个来自故事板的标识符,做这样的事情

     UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:@"Your_Story_Board_Name" bundle:nil];
     TabViewController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:@"TAB_Identifier"];
     [self presentViewController:tabBarController animated:YES completion:nil];  
    

    希望对你有帮助

    【讨论】:

      【解决方案3】:

      首先将“tabbarid”赋予情节提要内的该选项卡

      UITabBarController *tabBarController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"tabbarid"];
          tabBarController1.selectedIndex = 1;
          [self presentViewController:tabBarController1 animated:YES completion:nil];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-21
        • 2014-07-27
        • 2011-08-22
        • 1970-01-01
        • 2019-07-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多