Search code examples
objective-ccocoansdatepicker

NSDatePicker becomeFirstResponder


I have a data entry form where the first field the user wants to enter is an NSDatePicker. I wish this field to be highlighted when the user clicks a button (labelled 'New')

I have tried putting in [myDatePicker becomeFirstResponder] but this has no effect.

Can anybody show me how to set the focus to myDatePicker?


Solution

  • Unfortunately, becomeFirstResponder does not work that way.

    As mentioned in the docs, you should send makeFirstResponder: to the window that contains the control you wish to become the first responder. In your case the window that holds your NSDatePicker.

    becomeFirstResponder can be overridden in a control to return false if you do not want it to become the first responder.