Search code examples
macoscocoansdatepicker

NSDatePicker nextKeyView


It seems that the NSDatePicker nextKeyView is never taken into account.

I can key tab to the NSDatePicker, but never get out of it though nextKeyView is correctly set.

When inside the picker, if I press the tab key, the focus goes correctly from day to month to year text fields, but is sticked in year text field and does never go to the nextKeyView control.

Same thing in the reverse direction, shift-tab goes correctly from year to month to day but is sticked there inside the NSDatePicker.

I guess this is a bug of NSDatePicker.

How can I subclass (or any other type of solution) to overcome this problem ?

enter image description here Also, a log of the next key view chain, just to prove they are set

Initial first responder <NSTextField: 0x100587c60>
next key view <NSDatePicker: 0x6000035008f0>
next key view <NSComboBox: 0x100636740>
next key view <NSTextField: 0x10063e5a0>
next key view <NSTextField: 0x100587c60>

Solution

  • Here is the catch : The controller that manages the view has a keyDown: method, because it needs to react on a "delete" key down. This method was not calling [super keyDown:event] if the pressed key was not "delete" (such as the "tab" key).

    Adding the call to super when the key is not to be handled by the controller solved the problem.

    Why was a tab key pressed handled correctly in some cases (e.g. when focus is on a text field) and not other cases (e.g. date picker) remains unexplained.

    Thanks to all the persons that posted comments and help me figure this out.