gpt4 book ai didi

swift - NSAlert() runmodal 此类对于键 modalWindow 不符合键值编码

转载 作者:行者123 更新时间:2023-11-30 10:33:08 25 4
gpt4 key购买 nike

最近我将我的 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
}

请注意,我仅在最新的操作系统 Catalina 中遇到此问题,在以前的操作系统中我没有遇到任何问题。

关于swift - NSAlert() runmodal 此类对于键 modalWindow 不符合键值编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58657332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com