我有一个自定义NSControl
,我正在尝试使该功能edit(withFrame:editor:delegate:event:)
正常工作。在调用它时,我希望字段编辑器会出现在我的视图中,但没有任何反应。
我已经阅读了该函数的文档,并创建了一个最小的示例:
class MyView: NSControl, NSControlTextEditingDelegate, NSTextDelegate {
required init?(coder: NSCoder) {
super.init(coder: coder)
isEnabled = true
}
override func mouseDown(with event: NSEvent) {
let editor = window!.fieldEditor(true, for: nil)!
let rect = bounds.insetBy(dx: 10.0, dy: 10.0)
self.edit(withFrame: rect, editor: editor, delegate: self, event: event)
}
func control(_ control: NSControl, textShouldBeginEditing fieldEditor: NSText) -> Bool {
return true
}
func control(_ control: NSControl, textShouldEndEditing fieldEditor: NSText) -> Bool {
self.endEditing(fieldEditor)
return true
}
func textShouldBeginEditing(_ textObject: NSText) -> Bool {
return true
}
}
从示例中可以看出,我不太确定是否符合NSControlTextEditingDelegate
or NSTextDelegate
。我实现的所有功能似乎都没有被调用。
还是我可能误解了该功能的目的?我应该覆盖它而不是调用它吗?