This seems simple, but essential.
Place an NSDatePicker (style: graphical) into a window, build & run, then attempt to use arrow keys to move around. The only response is a 'ding' from the computer.
I've overridden -keydown
in a simple custom NSDatePicker subclass and printed theEvent to notice they have corresponding keyCodes of 123 through 126.
Then, I stumbled upon resetting the date picker's date after each arrow button press, inside -keydown
, like so:
- (void)keyDown:(NSEvent *)theEvent
switch ([[theEvent valueForKey:@"keyCode"] integerValue]) {
case 126:
// Take away one week from the date
self.dateValue = [NSDate dateWithTimeInterval:-604800 sinceDate:self.dateValue];
break;
.... similar for 125 - 123 ...
}
}
Implementing this method has the side effect of taking away the 'tab' key for stepping through objects.
This seems like a big work-around. Is there another way already included in the date picker??
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…