1

I have a 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]);

}

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)?

EDIT

I only have the method to be selected.

enter image description here

And this is connection inspector. enter image description here

prosseek
  • 182,215
  • 215
  • 566
  • 871

2 Answers2

4

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

danyowdee
  • 4,658
  • 2
  • 20
  • 35
-1

You typically want to add a target and action for a particular event. When you are making a connection using IB, look at the Connections Inspector. There is a list of control events to which you can set a target-action pair. Choose an event and drag to an action method.

MHC
  • 6,405
  • 2
  • 25
  • 26
  • I checked the connection inspector, and I couldn't find the event. Could you elaborate the answer? Thanks. – prosseek Mar 14 '11 at 19:28
  • @prosseek that advice doesn't apply on the Mac as of OS 10.6 as it is specific to UIKit. I don't know about Lion, though. – danyowdee Mar 14 '11 at 21:08