我发现了:https://developer.apple.com/documentation/appkit/nscontroltexteditingdelegate/1428925-control
optional func control(_ control: NSControl,
textView: NSTextView,
completions words: [String],
forPartialWordRange charRange: NSRange,
indexOfSelectedItem index: UnsafeMutablePointer<Int>) -> [String]
有人可以在任何示例中说明如何使用吗?我不太明白。
我试图实现这一点,但是没有任何效果。您可以在下面找到我的代码。
提前谢谢您
class ViewController: NSViewController, NSTextFieldDelegate {
@IBOutlet weak var InputField: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
InputField.delegate = self
}
func control(_ control: NSControl, textView: NSTextField, completions words: [String], forPartialWordRange charRange: NSRange, indexOfSelectedItem index: UnsafeMutablePointer<Int>) -> [String] {
let words = ["Hello", "Brother"]
return words
}
}
因此,如果您不想自定义建议,则只需返回单词:
optional func control(_ control: NSControl,
textView: NSTextView,
completions words: [String],
forPartialWordRange charRange: NSRange,
indexOfSelectedItem index: UnsafeMutablePointer<Int>) -> [String] {
return words
}