[英]Present view from app delegate with a tabbar Controller-> Nav controller -> View Hierarchy - iOS Swift
我搜索了整个SO,发现了类似的文章,但是没有一种解决方案适合我。 下面是我的视图层次的屏幕截图
我尝试过的众多代码片段之一如下:
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
})
上面的代码使用导航栏显示了正确的选项卡,但是没有选项卡。
我想要一个强制触摸按钮,该选项卡向该标签提供导航栏,而该标签栏则存在,有人知道该怎么做吗?
目前,我无法对此进行全面测试,但我相信您不会在标签栏中显示视图控制器。 您可以设置其视图控制器项和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()才能实际显示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.