Question

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?

Was it helpful?

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.

OTHER TIPS

Is your picker linked to a textfield for the output? I have linked custom pickers to my textfields keyboard property before. If the output is set to the textfield, you can make the textfield the first responder and the picker will come up in place of the keyboard.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top