使用 ARKit 的非常简单的 Swift 代码。主要是让Xcode创建一个ARKit App并运行。我工作正常并展示了 de Plane。
但是,当向 Storyboard 添加一个导航 Controller 并创建一个小菜单时,带有 Plane Demo 的条目并现在调用相同的 ARKit 示例,应用程序崩溃。
switch menuItemIndex {
case 0:
let controller = AvionViewController()
self.navigationController?.pushViewController(controller, animated: true)
default:
print("something")
}
崩溃是:
2017-06-27 08:08:26.317187-0500 ARDemo[1868:432582] [DYMTLInitPlatform] platform initialization successful fatal error: unexpectedly found nil while unwrapping an Optional value 2017-06-27 08:08:29.546679-0500 ARDemo[1868:432449] fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
这意味着,当直接运行 ARKit 演示 ViewController 时,它可以工作,但是当从另一个调用 ViewController 时,应用程序会崩溃。
另一方面,当不使用@IBOutlet 时,以编程方式创建 ARSCNView 并添加到 View 中,应用程序运行正常。
在 Objective-C 中做同样的事情不会产生任何崩溃。奇怪吗?
有什么想法吗?
最佳答案
如果您使用 Storyboard进行导航,那不是您应该实例化 View Controller 的方式。
你必须调用 let controller = self.storyboard?.instantiateViewController(withIdentifier: "yourViewControllersStoryboardID")
关于swift - ARKit Swift - fatal error : unexpectedly found nil while unwrapping an Optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44781256/