问题
I have a NSTextField with some text "sometext". How can I place the cursor between e and t: "some|text" programmatically?
回答1:
You need to set your text field current editor selected range property. Try like this:
textField.currentEditor()?.selectedRange = NSRange(location: 4, length: 0)
You will need to call displayIfNeeded
textField.displayIfNeeded()
来源:https://stackoverflow.com/questions/34246319/swift-set-insertion-point-in-nstextfield