Search code examples
swiftcocoanstextfield

Delete command is not working for NSTextField


I have a textfield to which I need to listen to tab key, so that when ever the user press tab from that text field I can move the focus to next text field. I have implemented the below code to perform that operation.

func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
    if (commandSelector == #selector(insertTab)) {
        if control == firstTextField {
            makeNextTextFieldAsFirstResponder()
        }
    }
    return true
}

My problem is that as I have implemented this code, delete key is not doing what it suppose to do(removing last character from the text field's text). Am I missing something here?

I am new to Mac development so excuse me if this question has been asked already somewhere.


Solution

  • I found the solution to my own problem. It turns out to be a simple mistake. I am not sure about how exactly this method works and how the return value affect the nature of the text field as I am new to Mac development, but it seems that the default return value should be false. Any insights to this behaviour are welcome.