回答編集履歴
1
swift版追加
answer
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
afterDelay:NSEvent.doubleClickInterval];
|
25
25
|
}
|
26
26
|
|
27
|
-
// ダ
|
27
|
+
// ダブルクリック時のアクション
|
28
28
|
- (IBAction)doubleClick:(id)sender {
|
29
29
|
[self cancelSingleAction];
|
30
30
|
|
@@ -32,7 +32,37 @@
|
|
32
32
|
}
|
33
33
|
```
|
34
34
|
|
35
|
+
```swift
|
36
|
+
// シングルクリック時のアクションをキャンセル
|
37
|
+
func cancelSingleAction() {
|
38
|
+
type(of: self).cancelPreviousPerformRequests(withTarget: self)
|
39
|
+
}
|
40
|
+
|
41
|
+
// シングルクリック時のアクション
|
42
|
+
func singleAction(_ sender: Any?) {
|
43
|
+
print("Single")
|
44
|
+
}
|
45
|
+
|
46
|
+
// NSTableView.actionに設定するアクション
|
47
|
+
@IBAction func singleClick(_ sender: Any?) {
|
48
|
+
cancelSingleAction()
|
49
|
+
perform(#selector(singleAction(_:)),
|
50
|
+
with: sender,
|
51
|
+
afterDelay: NSEvent.doubleClickInterval())
|
52
|
+
}
|
53
|
+
|
54
|
+
// ダブルクリック時のアクション
|
55
|
+
@IBAction func doubleClick(_ sender: Any?) {
|
56
|
+
cancelSingleAction()
|
57
|
+
|
58
|
+
print("Double")
|
59
|
+
}
|
60
|
+
```
|
61
|
+
|
35
62
|
簡単に説明すると
|
36
63
|
- NSEvent.doubleClickIntervalが過ぎるまでシングルクリック時のアクションを遅延させる
|
37
64
|
- ダブルクリックされたら遅延中のアクションをキャンセルしダブルクリックのアクションを行う
|
38
|
-
- アクションの遅延中に別のセルがクリックされたら遅延中のアクションをキャンセルし、新たにアクションを遅延させる
|
65
|
+
- アクションの遅延中に別のセルがクリックされたら遅延中のアクションをキャンセルし、新たにアクションを遅延させる
|
66
|
+
|
67
|
+
|
68
|
+
`cancelPreviousPerformRequests(withTarget:)`はそのクラスのインスタンスが実行した`perform(_:, with:, afterDelay:)`の実行のみをキャンセルします。
|