NSDatePicker 更改日期方法运行两次!(mac app)
我只是在表单中添加一个 NSDatePicker,设置样式图形,然后设置如下操作:
[datePicker setAction:@selector(datePickSelected:)];
在方法中,它只是打印出选定的日期。
-(void)datePickSelected:(id)sender
{
NSLog(@"%@",[datePicker dateValue]);
}
它可以工作,但当您单击此日期选择器中的日期时会运行两次。这是为什么呢?
2011-05-25 15:17:09.382 xxx[6609:a0f] 2011-05-13 15:17:04 +0800
2011-05-25 15:17:09.677 xxx[6609:a0f] 2011-05-13 15:17:04 +0800
I just add one NSDatePicker to the form, set the style graphical, and set the action like this:
[datePicker setAction:@selector(datePickSelected:)];
in the method, it just prints out the selected date.
-(void)datePickSelected:(id)sender
{
NSLog(@"%@",[datePicker dateValue]);
}
It works, but runs two times when you click the date in this datepicker. Why is this?
2011-05-25 15:17:09.382 xxx[6609:a0f] 2011-05-13 15:17:04 +0800
2011-05-25 15:17:09.677 xxx[6609:a0f] 2011-05-13 15:17:04 +0800
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
执行此操作可以解决此问题:
Do this to fix this:
这是一个 Swift 4 解决方案,其中
NSDatePicker
位于NSViewController
中:Here's a Swift 4 solution with the
NSDatePicker
inside anNSViewController
:第一个答案对我不起作用。我现在在 Swift 中使用这个:(
但有点奇怪,现在在 mouseDown 而不是 mouseUp 上调用该操作,但这对我来说现在并不重要......)
The first answer doesn't work for me. I use this now in Swift:
(But it's a little bit strange, the action is now called on mouseDown instead of mouseUp, but that doesn't matter for me now...)