我正在将NSTextField
与求和配合使用,通过按F5
键,它们可以正常工作。
但是我必须以编程方式调用complections,为此我正在使用complete(:)
,但是每次我遇到错误都会崩溃我试图打电话给InputField.complete(nil)
。
您可以在下面找到我的代码。
提前谢谢您
class ViewController: NSViewController, NSTextFieldDelegate, NSControlTextEditingDelegate {
@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
}
@IBAction func CompleteButton(_ sender: NSButton) {
print("pressed")
InputField.complete(nil)
}
}
但是,如果我尝试按下按钮,则会在控制台中显示:
pressed
[NSTextField complete:]: unrecognized selector sent to instance 0x10066ae00
[General] -[NSTextField complete:]: unrecognized selector sent to instance 0x10066ae00
此作品:
@IBAction func completeButton(_ sender: NSButton) {
inputField.currentEditor()?.complete(nil)
}