swift - 显示另一个窗口时应用程序崩溃,但仅在未调试时
问题描述
我是一名尝试制作小型 macOS 应用程序的 iOS 开发人员。我有故事板,并且有两个 NSWindowController 和他们的 viewController。
单击第一个(初始)控制器中的按钮时,我想要另一个窗口(及其 viewController)。我尝试了两件事:
- 在 VC1 和 Window2 之间创建一个 segue,命名并调用它。
- 用 实例化
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)
}
}
解决方案
我想到了。提供的错误并不清楚,但经过多次测试后,我注意到它有时会显示不同的错误。我发现有人提到了我放在下一个视图中的 WebView。我只是写import WebKit
在我需要的文件中,并没有将它添加到项目常规选项卡中的链接框架中。不知道为什么这个 100% 没有在调试器中崩溃,并且 100% 在产品上崩溃,但是哦,好吧。
推荐阅读
- r - 如果它们具有相同的值,则删除数据框中的组
- excel - 使用 VBA 按钮在 Excel 工作表中复制粘贴行/单元格
- c# - GMT时间和UTC时间不相同
- google-sheets - Google 表格的查询以查找包含在字符串末尾的内容
- java - debezium/kafka 从本地 api 消费主题
- c# - Arduino Serial.println 仅正确打印第一个字符
- php - 使用 Ajax 调用设置会话时出现不可预测的行为
- performance - 提高 PowerShell 函数从 CSV 中删除重复项的性能
- anylogic - 在 AnyLogic 中计算司机工资
- php - nodejs应用程序的PHP子进程不输出任何内容