NSTextField:在swift 5中由.complete(nil)调用补全时发生错误

问题描述 投票:0回答:1

我正在将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
swift autocomplete delegates nstextfield nstextview
1个回答
0
投票

此作品:

@IBAction func completeButton(_ sender: NSButton) {
    inputField.currentEditor()?.complete(nil)
}
© www.soinside.com 2019 - 2024. All rights reserved.