我有一个嵌入在导航控制器内部的视图控制器。此导航控制器是我的标签栏控制器内的第三个项目。我想以模态方式呈现视图控制器。
这是我尝试过的,但它没有运行
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
// CameraView is the Storyboard ID of the VC I want to present
if viewController is EditPreviewVideosViewController {
if let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: "CameraView") {
// None of this prints
print()
print("new vc is allowed")
print()
tabBarController.navigationController?.present(newVC, animated: true, completion: {
print("complete")
})
return false
}
}
return true
}
答案 0 :(得分:0)
从tabbarController孩子
获取正确的导航控制器if let nav = tabBarController.viewControllers[tabBarController.selectedIndex] as UINavigationController {
nav.present(newVC, animated: true, completion: {
print("complete")
})
}
答案 1 :(得分:0)
您正在错误的故事板中找到视图控制器
这一行
let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: ....
应该是
let newVC = UIStoryboard.init(name: "NameOfYourStoryboardContainsVideo", bundle: nil).instantiateViewController(withIdentifier: "CameraView")
现在你的if会正确执行