Search code examples
swiftxcodemacoskeydownnstextfield

Select next NSTextField with Tab key in Swift


Is there a way to change the responder or select another textfield by pressing tab on the keyboard, in Swift?

enter image description here

Notes: It's for a fill in the blank type application.

My VC creates a list of Words [Word], and each of those words has its own WordView - word.wordView. The WordView is what is displayed. WordView is a child of NSTextField.

I tried to override keydown but it doesn't allow me to type anything in the text view.


Solution

  • You have to connect your textField nextKeyView to the next textField through the IB or programmatically:

    textField1.nextKeyView = textField2
    

    enter image description here