我在整个S.O搜索并找到了类似的文章,但没有一个解决方案适合我。下面是我的视图层次结构的屏幕截图
我尝试过的众多代码片段之一如下:
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
})
上面的代码显示了带有导航栏的正确选项卡,但没有tabor存在。
我想要一个强制触摸按钮,它会显示带有导航栏和标签栏的标签,是否有人知道如何操作?
答案 0 :(得分:4)
我目前无法对此进行全面测试,但我相信在标签栏中,您不会显示视图控制器。您设置其视图控制器项和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()来实际显示