首页 > 解决方案 > 显示另一个窗口时应用程序崩溃,但仅在未调试时

问题描述

我是一名尝试制作小型 macOS 应用程序的 iOS 开发人员。我有故事板,并且有两个 NSWindowController 和他们的 viewController。

单击第一个(初始)控制器中的按钮时,我想要另一个窗口(及其 viewController)。我尝试了两件事:

  1. 在 VC1 和 Window2 之间创建一个 segue,命名并调用它。
  2. 用 实例化self.storyboard?.instantiate(..)

这两项工作 - 当我通过 Xcode 运行它时。但是如果我关闭 Xcode 并只运行生成的产品,它会在我尝试打开下一个 viewController 时立即崩溃,并说:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Illegal instruction: 4
Termination Reason:    Namespace SIGNAL, Code 0x4
Terminating Process:   exc handler [32282]

Application Specific Information:
Performing @selector(ok:) from sender _NSPaddedButton 0x600003d0ac40

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   com.my.app              0x000000010d3e998e FirstViewController.openFile(at:) + 734 (SecondViewController.swift:44)
1   com.my.app              0x000000010d3e95e9 closure #1 in FirstViewController.openFile(_:) + 249 

我现在用它来实例化它:

if let w = storyboard?.instantiateController(withIdentifier: "secondWindowIdentifier") as? NSWindowController{
    if let d = w.contentViewController as? SecondViewController{
        d.doSomething(someData: myData)
        self.presentAsModalWindow(d)
    }
}

标签: swiftxcodemacos

解决方案


我想到了。提供的错误并不清楚,但经过多次测试后,我注意到它有时会显示不同的错误。我发现有人提到了我放在下一个视图中的 WebView。我只是写import WebKit在我需要的文件中,并没有将它添加到项目常规选项卡中的链接框架中。不知道为什么这个 100% 没有在调试器中崩溃,并且 100% 在产品上崩溃,但是哦,好吧。


推荐阅读