gpt4 book ai didi

ios - 以编程方式导航到另一个 Storyboard上的 navigationcontroller 和 tabbarcontroller 内的 viewcontroller

转载 作者:搜寻专家 更新时间:2023-11-01 06:34:23 25 4
gpt4 key购买 nike

我需要以编程方式从另一个 Storyboard 转到 View Controller 。从这里开始很容易。但问题是:viewController 嵌入在导航 Controller 中,而这个嵌入到 tabBarController 中(见图)

enter image description here

我试过:

    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)

我得到的是:我转到正确的 Controller ,导航 Controller 工作,但没有 tabbarcontroller

另一个尝试:

    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)

在这种情况下,tabbar 可以工作,但没有 navigationcontroller。

然后...尝试第 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)

在这种情况下,行为很奇怪...我出现在正确的 Controller 中,但带有后退按钮。如果我单击我会转到相同的正确 Controller ...使用 tabbarcontroller...然后导航 Controller 消失...很好 :S

有没有办法以编程方式转到正确的 Controller 并开始使用标签栏和导航?

最佳答案

试试下面的代码:

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

我对 swift 的了解较少。上面的 Objective-C 代码是:

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

关于ios - 以编程方式导航到另一个 Storyboard上的 navigationcontroller 和 tabbarcontroller 内的 viewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43235247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com