gpt4 book ai didi

ios - 当前 View Controller 嵌入在导航 Controller 中,与选项卡栏 Controller 模态分开

转载 作者:行者123 更新时间:2023-11-30 11:58:59 26 4
gpt4 key购买 nike

我有一个嵌入在导航 Controller 内的 View Controller 。该导航 Controller 是我的选项卡栏 Controller 中的第三个项目。我想以模态方式呈现 View Controller 。

这是我尝试过的,但它不运行

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
}

最佳答案

从 tabbarController 子级获取正确的导航 Controller

if let nav = tabBarController.viewControllers[tabBarController.selectedIndex] as UINavigationController {

nav.present(newVC, animated: true, completion: {
print("complete")
})
}

关于ios - 当前 View Controller 嵌入在导航 Controller 中,与选项卡栏 Controller 模态分开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47467944/

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