[英]NSAlert() runmodal this class is not key value coding-compliant for the key modalWindow
Recently i upgraded my mac to Catalina and seeing weird issues with NSAlert().最近我将我的 mac 升级到 Catalina,发现 NSAlert() 出现了奇怪的问题。
When ever any alert is opened i am getting bellow error in console and the alert is automatically closing, without any user clicking on OK button.每当打开任何警报时,我都会在控制台中收到以下错误,并且警报会自动关闭,而无需任何用户单击“确定”按钮。
Error in console:控制台错误:
this class is not key value coding-compliant for the key modalWindow.' with user dictionary {
NSTargetObjectUserInfoKey = "<ProjectName.AppDelegate: 0x100b07400>";
NSUnknownUserInfoKey = modalWindow;
}
Below is my code for displaying Alert.下面是我显示警报的代码。
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()
FYI: This is Mac App, using swift, Xcode11 (tried with Xcode 11.1 & 11.2)仅供参考:这是 Mac 应用程序,使用 swift、Xcode11(与 Xcode 11.1 和 11.2 一起尝试)
Finally figured it,终于想通了
In my application we do support for scripting so i added below code in AppDelegate file:在我的应用程序中,我们确实支持脚本,所以我在 AppDelegate 文件中添加了以下代码:
func application(_ sender: NSApplication, delegateHandlesKey key: String) -> Bool {
return true
}
Since i am returning true always it is creating issues with NSOpenPanels, NSSavePanels and NSAlert, and i changed the code as below and it is working fine without any issues.因为我总是返回 true,所以它会在 NSOpenPanels、NSSavePanels 和 NSAlert 方面产生问题,我将代码更改如下,它工作正常,没有任何问题。
func application(_ sender: NSApplication, delegateHandlesKey key: String) -> Bool {
if key == "[.sdf file KEY HERE]"{
return true
}
return false
}
Please note i am getting this issues only in latest OS Catalina, in previous OS i didn't got any issues.请注意,我只在最新的 OS Catalina 中遇到此问题,在以前的 OS 中我没有遇到任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.