简体   繁体   English

以编程方式导航到另一个故事板上的navigationcontroller和tabbarcontroller内的viewcontroller

[英]Navigate programmatically to viewcontroller inside navigationcontroller & tabbarcontroller on another storyboard

I need to go programmatically to a viewcontroller from another Storyboard. 我需要以编程方式从另一个Storyboard转到viewcontroller。 From here easy. 从这里轻松。 But the problem is: that viewController is embedded in a navigation controller, and this one into a tabBarController (see image) 但问题是:viewController嵌入在导航控制器中,而这一个嵌入了tabBarController(见图)

在此输入图像描述

I've tried: 我试过了:

    let storyboard = UIStoryboard(name: "Inside", bundle: nil)

    let viewcontroller = storyboard.instantiateViewController(withIdentifier: "controller_id")
    let navigationController = UINavigationController(rootViewController: viewcontroller)

    self.present(navigationController, animated: true, completion: nil)

What I get with this is: I go to the correct controller, with navigation controller working, but no tabbarcontroller 我得到的是:我去了正确的控制器,导航控制器工作,但没有tabbarcontroller

Another try: 另一个尝试:

    let storyboard = UIStoryboard(name: "Inside", bundle: nil)

    let tabbar = storyboard.instantiateViewController(withIdentifier: "tab_id")
    let navigationController = UINavigationController(rootViewController: tabbar)

    self.present(navigationController, animated: true, completion: nil)

In this case, tabbar is working, but no navigationcontroller. 在这种情况下,tabbar正在工作,但没有navigationcontroller。

And... try number 3: 并且...尝试3号:

    let storyboard = UIStoryboard(name: "Inside", bundle: nil)
    let tabbar = storyboard.instantiateViewController(withIdentifier: "tab_id")
    let viewcontroller = storyboard.instantiateViewController(withIdentifier: "race_id")

    let navigationController = UINavigationController(rootViewController: tabbar)

    navigationController.pushViewController(viewcontroller, animated: false)

    self.present(navigationController, animated: true, completion: nil)

In this case, the behaviour is so strange... I appear in the correct controller, but with a back button. 在这种情况下,行为是如此奇怪...我出现在正确的控制器,但有一个后退按钮。 If I click I go to the same correct controller... with the tabbarcontroller... and then navigationcontroller disappear... nice :S 如果我点击我去同一个正确的控制器...使用tabbarcontroller ...然后navigationcontroller消失...很好:S

Any way to go programmatically to the correct controller and get working the tabbar & navigation? 有没有办法以编程方式进入正确的控制器并开始使用tabbar和导航?

Try out below code: 试试下面的代码:

var storyBoard = UIStoryboard(name: "SecondStoryboard", bundle: nil)
var tabbar: UITabBarController? = (storyBoard.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)
navigationController?.pushViewController(tabbar, animated: true)

I have less knowledge in swift. 我对swift的了解较少。 Objective-C code for the above is: 上面的Objective-C代码是:

    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];
    UITabBarController *tabbar = (UITabBarController *)[storyBoard instantiateViewControllerWithIdentifier:@"tabbar"];
    [self.navigationController pushViewController:tabbar animated:YES];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过NavigationController-TabBarController-NavigationController以编程方式导航 - Navigate programmatically through NavigationController-TabBarController-NavigationController 在TabBarController内部的NavigationController中从(Table)ViewController呈现模态ViewController - Presenting Modal ViewController from (Table)ViewController inside a NavigationController inside a TabBarController 在ViewController中以编程方式使用NavigationController - Programmatically use NavigationController inside ViewController Swift-TabBarController-> ViewController-> NavigationController - Swift - TabBarController -> ViewController -> NavigationController 如何从一个故事板导航到另一个 TabBarController? - How to navigate from one storyboard to another TabBarController? 以编程方式将NavigationController添加到指定viewController中,而无需故事板快速 - Add navigationController to specif viewController programmatically without storyboard swift 如何在 swift 故事板中的另一个 TabBarController 中制作 TabBarController? - How to make TabBarController inside another TabBarController in swift storyboard? 如何从TabBarController内部的NavBarController中显示ViewController故事板元素 - How to Reveal ViewController Storyboard Elements from a NavBarController inside of a TabBarController TabBarController 中的 NavigationController,反之亦然? - NavigationController inside TabBarController, or vice versa? 导航模态视图控制器和导航控制器的层次结构 - navigate the hierarchy of modal viewcontroller and navigationcontroller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM