swift - ARKit Swift - fatal error : unexpectedly found nil while unwrapping an Optional value

标签 swift xcode arkit

使用 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/

相关文章:

swift - 使用核心数据索引从核心数据中获取特定项目

ios - Swift如何将tableView移回GroundView标签

xcode - Swift:通过代码更改 Storyboard上元素的位置

objective-c - 如何使用 ipad 的 objective-c 发送/接收 soap 对象

ios - Swift - 在类中定义属性

swift - SCNCamera.exposureOffset 在 iOS13 中不起作用

swift - iTunes 是否备份核心数据?

swift - 使用真实世界方位在 ARKit 场景中定向 SCNNode

java - ARCore – 如何将真实世界对象放置在 3d 模型前面?

ios - 关闭一个 View Controller,然后呈现一个 Alert Controller