The action is called twice (mouse up / down) when clicking on Cocoa / objective-c


I have a NSDatePicker (target), and datePickerAction (action)

- (IBAction)datePickerAction:(id)sender

    if( [[[NSApplication sharedApplication] currentEvent] modifierFlags] &
       NSShiftKeyMask )
        NSLog(@"shift pressed %@", [datePicker dateValue]);

        NSLog(@"hello %@", [datePicker dateValue]);


It works well as when I click a date in NSDatePicker object, the method(action) is called, the problem is that the method is called twice - mouse down/up.

Can I make the method called only once (up or down)?


I only have the method to be selected.

And this is connection inspector.

Unfortunately, I think you cannot set NSDatePicker (or NSDatePickerCell, to be specific) up this way in Interface Builder, but instead have to do it programmatically.

Here's a workaround that performs fine for me:

- (void)awakeFromNib
    // Assuming @property (assign) IBOutlet NSDatePickerCell *pickerCell;
    [self.pickerCell sendActionOn:NSLeftMouseDown]; // or NSLeftMouseUp or what have you...

Note that you cannot use NSLeftMouseDownMask here! (Well, of cause you can...but it won't help.)