質問

I have an NSDatePicker with text and stepper. The steppers show behavior that I find quite unintuitive. If my date picker is at the 26th of April and I select the day number, then click "up" a few times, the date picker cycles back to April 1st after the 30th!

enter image description here

How do I make the picker continue into May?

役に立ちましたか?

解決

You might be able to use the delegate method - (void)datePickerCell:(NSDatePickerCell *)aDatePickerCell validateProposedDateValue:(NSDate **)proposedDateValue timeInterval:(NSTimeInterval *)proposedTimeInterval as it sends a message whenever the date changes, however it does not inform whether the change was made through the buttons or through keyboard, so if the user manually changed the date from 30-04-2013 to 01-04-2013 you have no way of telling if they did it with the buttons or with the keyboard. You might be able to subclass the buttons to detect if a click happened, but I would say that's too much of a hassle. I would say this should be the least of your worries, or you could do what Robert Harvey suggested which is to use a dropdown calendar, which can be changed using the method [datePicker setDatePickerStyle:NSClockAndCalendarDatePickerStyle] or through interface builder.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top