vAp*_*App 2 xcode uinavigationcontroller ios swift
对于标签栏控制器的第二项,我有一个想要以模态方式呈现的导航控制器。我不断收到一条错误消息
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图以模态方式呈现活动控制器。”
然后我的应用程序崩溃并转到应用程序委托。
这是我到目前为止的代码
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if let restoreID = viewController.restorationIdentifier {
if restoreID == "NavigationCamera" {
if let nav = tabBarController.viewControllers![tabBarController.selectedIndex] as? UINavigationController {
print("Nav is allowed")
//let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: "CameraView")
tabBarController.present(nav, animated: true, completion: {
print("complete")
})
return false
}
}
}
return true
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您正在尝试呈现已在 UITabBarController 中处于活动状态的视图控制器,这就是应用程序崩溃的原因。尝试使用这个
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if let restoreID = viewController.restorationIdentifier {
if restoreID == "NavigationCamera" {
print("Nav is allowed")
let newVC = tabBarController.storyboard?.instantiateViewController(withIdentifier: "CameraView") as! UIViewController
tabBarController.present(UINavigationController.init(rootViewController: newVC), animated: true, completion: {
print("complete")
})
return false
}
}
return true
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10115 次 |
| 最近记录: |