I have a NSDatePicker (NSDatePicker* datePicker), and set its delegate as the main application (self). I programmed as follows.
Make self datePicker delegate
[[datePicker cell] setDelegate:self];
Set datePickerAction: to be called when control is clicked.
[datePicker setAction:@selector(datePickerAction:)];
This is the method.
- (IBAction)datePickerAction:(id)sender
{
if( [[[NSApplication sharedApplication] currentEvent] modifierFlags] &
NSShiftKeyMask )
NSLog(@"shift pressed %@", [datePicker dateValue]);
else
NSLog(@"hello %@", [datePicker dateValue]);
}
The problem is that delegation doesn't seem to work when I click the date in the NSDatePicker calendar.

You have to add this method to your code :
- (void)datePickerCell:(NSDatePickerCell *)aDatePickerCell validateProposedDateValue:(NSDate **)proposedDateValue timeInterval:(NSTimeInterval *)proposedTimeInterval
{
NSString *aDate = [myDateFormat stringFromDate:*proposedDateValue];
}
From IB, select the DatePickerCell, right click, drag the delegate entry to the File's Owner box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With