OSX NSTextView 在显示 NSAlert、NSOpenPanel 后变得不可编辑

OSX NSTextView becomes uneditable after showing NSAlert,NSOpenPanel

我的视图中有一个 NSTextView,它可以正常工作,但是当我显示 NSAlert 并关闭它时,它变得不可编辑(文本仍然可选择)。 NSAlert 是一个 save/cancel 警报,当用户选择保存时更新 textView 的字符串,当用户按下取消时不会更新字符串。在这两种情况下,textView 都是不可编辑的,当用户进行了更改并想要更改 tableView 选择时,会显示警报。

感觉 textView 拒绝了 first responder 但当打破并检查控制台时 "true",在视图不可编辑后我还检查了一些其他值:

我的 "test" 设置:

视频,从表格视图选择更改和按钮触发弹出窗口时相同:video

我的弹窗代码

func dialogOKCancel(question: String, text: String) -> Bool {
        let myPopup: NSAlert = NSAlert()
        myPopup.messageText = question
        myPopup.informativeText = text
        myPopup.alertStyle = NSAlertStyle.warning
        myPopup.addButton(withTitle: "OK")
        myPopup.addButton(withTitle: "Cancel")

        return myPopup.runModal() == NSAlertFirstButtonReturn
    }

let answer = self.dialogOKCancel(question: "Ok?", text: "Choose your answer.")

也尝试过:

        let a = NSAlert()
        a.messageText = "Delete the document?"
        a.informativeText = "Are you sure you would like to delete the document?"
        a.addButton(withTitle: "Delete")
        a.addButton(withTitle: "Cancel")
        a.alertStyle = NSAlertStyle.critical

        a.beginSheetModal(for: self.view.window!, completionHandler: { (modalResponse) -> Void in
            if modalResponse == NSAlertFirstButtonReturn {
                print("Document deleted")
            }
        })

我试过的东西:

我坚持了很长时间,非常感谢任何帮助, 谢谢

经过长时间的调试,我发现这一行是破坏​​文本字段的那一行,我会把它post留在网上,以防其他人偶然发现这个奇怪的问题

window?.styleMask = NSFullSizeContentViewWindowMask

删除此行解决了问题。