NSTextField 强制 becomeFirstResponder 删除文本

NSTextField force becomeFirstResponder removes text

在自定义 NSTableCellView 上使用 NSTextField。

当用户按下单元格上的任意位置时,我希望 NSTextField 成为第一响应者。 当我这样做时,文本消失了,用户需要按任意键盘键才能返回,如何禁用此行为?

代码:

    override func mouseDown(with event: NSEvent) {
        super.mouseDown(with: event)
        if (event.clickCount == 2) {
            self.beginEditing()
        } else {
            self.endEditing()
        }
    }

    private func beginEditing() {
        self.lblTitle.isEditable = true
        self.window?.makeFirstResponder(self.lblTitle)
        self.lblTitle.backgroundColor = Colors.clear
        self.lblTitle.borderColor = Colors.clear
    }

    private func endEditing() {
        self.lblTitle.isEditable = false
        self.lblTitle.backgroundColor = Colors.red
    }

删除这行解决了它

self.lblTitle.backgroundColor = Colors.clear
self.lblTitle.borderColor = Colors.clear