NSDatePicker misbehaving with arrow keys

霸气de小男生 提交于 2019-12-12 18:27:15

问题


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.

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.

来源:https://stackoverflow.com/questions/21269043/nsdatepicker-misbehaving-with-arrow-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!