回答編集履歴
1
swift版追加
test
CHANGED
@@ -50,7 +50,7 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
-
// ダ
|
53
|
+
// ダブルクリック時のアクション
|
54
54
|
|
55
55
|
- (IBAction)doubleClick:(id)sender {
|
56
56
|
|
@@ -66,6 +66,60 @@
|
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
+
```swift
|
70
|
+
|
71
|
+
// シングルクリック時のアクションをキャンセル
|
72
|
+
|
73
|
+
func cancelSingleAction() {
|
74
|
+
|
75
|
+
type(of: self).cancelPreviousPerformRequests(withTarget: self)
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
// シングルクリック時のアクション
|
82
|
+
|
83
|
+
func singleAction(_ sender: Any?) {
|
84
|
+
|
85
|
+
print("Single")
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
// NSTableView.actionに設定するアクション
|
92
|
+
|
93
|
+
@IBAction func singleClick(_ sender: Any?) {
|
94
|
+
|
95
|
+
cancelSingleAction()
|
96
|
+
|
97
|
+
perform(#selector(singleAction(_:)),
|
98
|
+
|
99
|
+
with: sender,
|
100
|
+
|
101
|
+
afterDelay: NSEvent.doubleClickInterval())
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
// ダブルクリック時のアクション
|
108
|
+
|
109
|
+
@IBAction func doubleClick(_ sender: Any?) {
|
110
|
+
|
111
|
+
cancelSingleAction()
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
print("Double")
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
```
|
120
|
+
|
121
|
+
|
122
|
+
|
69
123
|
簡単に説明すると
|
70
124
|
|
71
125
|
- NSEvent.doubleClickIntervalが過ぎるまでシングルクリック時のアクションを遅延させる
|
@@ -73,3 +127,11 @@
|
|
73
127
|
- ダブルクリックされたら遅延中のアクションをキャンセルしダブルクリックのアクションを行う
|
74
128
|
|
75
129
|
- アクションの遅延中に別のセルがクリックされたら遅延中のアクションをキャンセルし、新たにアクションを遅延させる
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
`cancelPreviousPerformRequests(withTarget:)`はそのクラスのインスタンスが実行した`perform(_:, with:, afterDelay:)`の実行のみをキャンセルします。
|
136
|
+
|
137
|
+
|