0

I have an NSDatePicker with text and a stepper which shows month/day/year (normal American date format). Right now, when I click the stepper without having anything selected, it defaults to changing the month; however, in the context of the app I'm building, it makes more sense to have it default to changing the day. I don't see anything in the class reference regarding how the stepper edits the date -- Is there any way I could subclass NSDatePicker to do this?

Matt Cooper
  • 2,042
  • 27
  • 43
  • 1
    Selecting the field to edit programmatically, can only be done by using `NSPickerDateCell` private methods. see [NSDatePicker, selecting elements, and field editors](http://www.cocoabuilder.com/archive/cocoa/303239-nsdatepicker-selecting-elements-and-field-editors.html#303250) – Emmanuel Mar 01 '14 at 19:40
  • @Emmanuel Thanks -- so does that mean this method would be impossible without access to source code, as the post in that link says, or does anyone have any ideas on what the private methods are? – Matt Cooper Mar 02 '14 at 05:09
  • 1
    That's mean that this method can change (or vanish) at any OS update, there is no documentation about it, and your application can be rejected from the Mac App Store if you use it. So if you still want to try to use it, get [class-dump](http://stevenygard.com/projects/class-dump/). – Emmanuel Mar 02 '14 at 08:59
  • Thanks, I'll try that. I'm distributing the app privately, not through the App Store. – Matt Cooper Mar 03 '14 at 14:02
  • https://stackoverflow.com/a/61734758/2303865 – Leo Dabus May 11 '20 at 18:34

1 Answers1

1

Just off the top of my head, here's my idea

Datepicker can be set to a specific NSDate, so make a stepper, and when it's pressed, if they pressed up

Find currentDate of your datePicker, find dateWithInterval from this date (1 day is 60 * 60 * 24 seconds)

set datePicker.date to this new date

I know it's not the most ideal solution, but if it's important for your app, it gives you a bit more control.

Logan
  • 52,262
  • 20
  • 99
  • 128
  • just for reference: a day might be `60 * 60 * 24`, `60 * 60 * 23` or `60 * 60 * 25` seconds long due to Daylight Saving Times. it might also be `60 * 60 * 24 + 1` seconds long due to leap seconds. – vikingosegundo Apr 14 '14 at 00:44