The action is called twice (mouse up / down) when Target is pressed in Cocoa / objective-c

I have NSDatePicker (target) and datePickerAction (action)

- (IBAction)datePickerAction:(id)sender
{

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

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

}

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

Is it possible to call a method only once (up or down)?

EDIT

I have only the method to choose.

enter image description here

And this is the connection inspector. enter image description here

+1
source share
2 answers

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

, :

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

, NSLeftMouseDownMask ! (, - ... .)

+4

. IB, . , . .

-1

All Articles