gpt4 book ai didi

ios - 使用标签栏 Controller-> Nav controller -> View Hierarchy 从 app delegate 呈现 View - iOS Swift

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

我搜索了整个 S.O 并找到了类似的文章,但没有一个解决方案适合我。下面是我的 View 层次结构的屏幕截图 enter image description here

我尝试过的许多代码片段之一如下:

            var storyBoard = UIStoryboard()
if UIDevice.current.userInterfaceIdiom == .pad {
storyBoard = UIStoryboard(name: "iPad", bundle: nil)
} else {
storyBoard = UIStoryboard(name: "Main", bundle: nil)
}


let tabVc = self.window?.rootViewController as! UITabBarController


let mynVC = storyBoard.instantiateViewController(withIdentifier: "nav") as! UINavigationController


let calcVc = storyBoard.instantiateViewController(withIdentifier: "destVc")


tabVc.present(mynVC, animated: true, completion: { () -> Void in
// Segue , do stuff

})

上面的代码显示了带有导航栏的正确选项卡,但是没有选项卡。

我想要一个强制触摸按钮来显示带有导航栏和标签栏的选项卡,有人知道该怎么做吗?

最佳答案

目前我无法对此进行全面测试,但我相信在标签栏中,您不会显示 View Controller 。您设置它的 View Controller 项和 selectedViewController 属性。

这应该可以,我会测试它并尽快更新,

var storyBoard = UIStoryboard()
if UIDevice.current.userInterfaceIdiom == .pad {
storyBoard = UIStoryboard(name: "iPad", bundle: nil)
} else {
storyBoard = UIStoryboard(name: "Main", bundle: nil)
}


let tabVc = self.window?.rootViewController as! UITabBarController

let mynVC = storyBoard.instantiateViewController(withIdentifier: "nav") as! UINavigationController

let calcVc = storyBoard.instantiateViewController(withIdentifier: "destVc")

tabVc.viewControllers = [mynVC]
tabVc.selectedViewController = mynVC

根据下面的其他内容,您可能还需要调用 window.setKeyAndVisible() 才能实际显示

关于ios - 使用标签栏 Controller-> Nav controller -> View Hierarchy 从 app delegate 呈现 View - iOS Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42652572/

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