NSDatePicker misbehaving with arrow keys

181 Views Asked by At

I have used NSDatePickers (without steppers) in the cells of a column in an NSTableView. The date pickers are used to set a duration of time in hours, minutes and seconds. If I highlight one of the controls and use the arrow keys to set the values, the date picker displays some weird behaviour:

  • Seconds increment by two for every time I press up arrow (whereas it should increment by one for each key press);
  • Seconds do not decrement when I press down arrow;
  • Every time I increment and decrement the minute and hour values, the seconds value also increases by one (each key press should only increment the selected value).

You can see this behaviour in the below example.

Image of weird NSDatePicker behaviour.

I have configured the NSDatePicker (result) as follows:

result = [[NSDatePicker alloc] initWithFrame:NSZeroRect];
result.identifier = @"timeCell";
result.tag = row;
[result setBordered:NO];
result.backgroundColor = [NSColor clearColor];
result.datePickerElements = NSHourMinuteSecondDatePickerElementFlag;
result.datePickerStyle = NSTextFieldDatePickerStyle;
result.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
[result setTarget:self];
[result setAction:@selector(timePickerDidChange:)];

Question: Does anyone know why this is happening and how I can fix it? Many thanks for your help.

PS: This question also touches on some weirdness surrounding arrow keys and NSDatePicker. It doesn't offer a solution though.

0

There are 0 best solutions below