问题描述
我有一个NSDatePicker(target)和datePickerAction(action)
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]);
}
在NSDatePicker对象中单击日期,方法(动作)被调用,问题是方法被调用两次 - 鼠标向下/向上。
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)?
我只有选择的方法。
>
这是连接检查器。
And this is connection inspector.
推荐答案
不幸的是,我想你不能设置 NSDatePicker
(或 NSDatePickerCell
)
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...
}
>不能在此处使用 NSLeftMouseDownMask
! (嗯,因为你可以...但它不会帮助。)
Note that you cannot use NSLeftMouseDownMask
here! (Well, of cause you can...but it won't help.)
这篇关于当在Cocoa / objective-c中单击目标时,将调用动作两次(鼠标向上/向下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!