在 Cocoa/objective-c 中单击 Target 时,操作会被调用两次(鼠标向上/向下)
我有一个 NSDatePicker (目标)和 datePickerAction (动作)
- (IBAction)datePickerAction:(id)sender
{
if( [[[NSApplication sharedApplication] currentEvent] modifierFlags] &
NSShiftKeyMask )
NSLog(@"shift pressed %@", [datePicker dateValue]);
else
NSLog(@"hello %@", [datePicker dateValue]);
}
当我单击 NSDatePicker 对象中的日期时,该方法(动作)被调用,问题是该方法被调用两次 - 鼠标向下/向上。
我可以让该方法只调用一次(向上或向下)吗?
编辑
我只有要选择的方法。
这是连接检查器。
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.
And this is connection inspector.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,我认为您无法在 Interface Builder 中以这种方式设置
NSDatePicker
(或具体而言,NSDatePickerCell
),而必须以编程方式进行设置。这是一个对我来说效果很好的解决方法:
请注意,您不能在这里使用
NSLeftMouseDownMask
! (嗯,当然你可以......但这没有帮助。)Unfortunately, I think you cannot set
NSDatePicker
(orNSDatePickerCell
, 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:
Note that you cannot use
NSLeftMouseDownMask
here! (Well, of cause you can...but it won't help.)您通常希望为特定事件添加目标和操作。当您使用 IB 建立连接时,请查看连接检查器。有一个控制事件列表,您可以为其设置目标操作对。选择一个事件并拖动到操作方法。
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.