NSAlert() runmodal this class 对于键 modalWindow 不符合键值编码
NSAlert() runmodal this class is not key value coding-compliant for the key modalWindow
最近我将我的 mac 升级到 Catalina,发现 NSAlert() 有奇怪的问题。
每当打开任何警报时,我都会在控制台中收到以下错误消息并且警报会自动关闭,而无需任何用户单击“确定”按钮。
控制台错误:
this class is not key value coding-compliant for the key modalWindow.' with user dictionary {
NSTargetObjectUserInfoKey = "<ProjectName.AppDelegate: 0x100b07400>";
NSUnknownUserInfoKey = modalWindow;
}
下面是我显示警报的代码。
let myPopup: NSAlert = NSAlert()
myPopup.messageText = messageText
myPopup.informativeText = infoText
myPopup.alertStyle = NSAlert.Style.warning
myPopup.addButton(withTitle: NSLocalizedString("OK", comment: "Button Text"))
let res = myPopup.runModal()
仅供参考:这是 Mac 应用程序,使用 swift、Xcode11(尝试使用 Xcode 11.1 和 11.2)
终于想通了,
在我的应用程序中,我们支持脚本,因此我在 AppDelegate 文件中添加了以下代码:
func application(_ sender: NSApplication, delegateHandlesKey key: String) -> Bool {
return true
}
因为我总是返回 true,所以它会导致 NSOpenPanels、NSSavePanels 和 NSAlert 出现问题,我按如下方式更改了代码,它工作正常,没有任何问题。
func application(_ sender: NSApplication, delegateHandlesKey key: String) -> Bool {
if key == "[.sdf file KEY HERE]"{
return true
}
return false
}
请注意,我仅在最新的 OS Catalina 中遇到此问题,在之前的 OS 中我没有遇到任何问题。
最近我将我的 mac 升级到 Catalina,发现 NSAlert() 有奇怪的问题。
每当打开任何警报时,我都会在控制台中收到以下错误消息并且警报会自动关闭,而无需任何用户单击“确定”按钮。
控制台错误:
this class is not key value coding-compliant for the key modalWindow.' with user dictionary {
NSTargetObjectUserInfoKey = "<ProjectName.AppDelegate: 0x100b07400>";
NSUnknownUserInfoKey = modalWindow;
}
下面是我显示警报的代码。
let myPopup: NSAlert = NSAlert()
myPopup.messageText = messageText
myPopup.informativeText = infoText
myPopup.alertStyle = NSAlert.Style.warning
myPopup.addButton(withTitle: NSLocalizedString("OK", comment: "Button Text"))
let res = myPopup.runModal()
仅供参考:这是 Mac 应用程序,使用 swift、Xcode11(尝试使用 Xcode 11.1 和 11.2)
终于想通了,
在我的应用程序中,我们支持脚本,因此我在 AppDelegate 文件中添加了以下代码:
func application(_ sender: NSApplication, delegateHandlesKey key: String) -> Bool {
return true
}
因为我总是返回 true,所以它会导致 NSOpenPanels、NSSavePanels 和 NSAlert 出现问题,我按如下方式更改了代码,它工作正常,没有任何问题。
func application(_ sender: NSApplication, delegateHandlesKey key: String) -> Bool {
if key == "[.sdf file KEY HERE]"{
return true
}
return false
}
请注意,我仅在最新的 OS Catalina 中遇到此问题,在之前的 OS 中我没有遇到任何问题。