Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up NSDatePicker delegate

I have a NSDatePicker (NSDatePicker* datePicker), and set its delegate as the main application (self). I programmed as follows.

  1. Make self datePicker delegate

    [[datePicker cell] setDelegate:self];

  2. 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.

enter image description here

  • Q : What's wrong with this delegation? The target/action method works fine.
  • Q : What document can I use for what delegation method is supported for NSDatePicker?
like image 940
prosseek Avatar asked Feb 02 '26 07:02

prosseek


1 Answers

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.

like image 101
fredzouille Avatar answered Feb 03 '26 19:02

fredzouille



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!