質問編集履歴
5
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -207,3 +207,13 @@
|
|
207
207
|
|
208
208
|
|
209
209
|
```
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
#### 対処したことを追記
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
双方のLongPressGedtureRecognizerに.cancelsTouchesInView = falseを設定。(SB上ではチェックを外す)したところ、
|
218
|
+
|
219
|
+
誤動作(SectionLongPressしてもCellLongPressが動く)することが稀になる。
|
4
表記追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
`tableView`がロングプレスされた際に、gestureの`location`からindexPathが取得できるのですが、Sectionをタップしても、ロングプレスしたSection直下のCellのindexpathしか取得できず(先頭のSectionだけは、ロングプレスすると、indexpathはnilと変換される。)、indexPathからロングプレスされたのがSectionかCellか判別することができません。location、view、subviewsあたりから取得できるcellとsectionを判別する基準があれば教えてください。
|
7
|
+
`tableView`がロングプレスされた際に、gestureの`location`からindexPathが取得できるのですが、Sectionをタップしても、ロングプレスしたSection直下のCellのindexpathしか取得できず(先頭のSectionだけは、ロングプレスすると、indexpathはnilと変換される。)、indexPathからロングプレスされたのがSectionかCellか判別することができません。senderに送られてくるlocation、view、subviewsあたりから取得できるcellとsectionを判別する基準があれば教えてください。
|
8
8
|
|
9
9
|
|
10
10
|
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,11 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
`tableView`がロングプレスされた際に、gestureの`location`からindexPathが取得できるのですが、Sectionをタップしても、
|
7
|
+
`tableView`がロングプレスされた際に、gestureの`location`からindexPathが取得できるのですが、Sectionをタップしても、ロングプレスしたSection直下のCellのindexpathしか取得できず(先頭のSectionだけは、ロングプレスすると、indexpathはnilと変換される。)、indexPathからロングプレスされたのがSectionかCellか判別することができません。location、view、subviewsあたりから取得できるcellとsectionを判別する基準があれば教えてください。
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
![![イメージ説明](f3d6bea709e42128c65134891b848d7f.gif)](4e7e61c16a8d275ff1631e797fef4f11.gif)
|
8
12
|
|
9
13
|
|
10
14
|
|
@@ -24,31 +28,35 @@
|
|
24
28
|
|
25
29
|
} else if (sender.state == UIGestureRecognizerState.ended) {
|
26
30
|
|
27
|
-
// タップされたCellのindexPathを取得する
|
28
|
-
|
29
|
-
let point = sender.location(in: leftTableView)
|
30
|
-
|
31
|
-
guard let indexPath = leftTableView.indexPathForRow(at: point) else { return }
|
32
|
-
|
33
31
|
|
34
32
|
|
33
|
+
let point = sender.location(in: leftTableView)
|
34
|
+
|
35
|
+
let indexPath = leftTableView.indexPathForRow(at: point)
|
36
|
+
|
37
|
+
|
38
|
+
|
35
|
-
|
39
|
+
// ここでSectionとCellで処理を分けたい
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
|
41
|
+
|
42
|
+
|
39
|
-
|
43
|
+
// gifでの表示用アラート
|
40
|
-
|
44
|
+
|
41
|
-
|
45
|
+
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
|
42
|
-
|
46
|
+
|
43
|
-
|
47
|
+
alert.title = "point/indexPath"
|
48
|
+
|
44
|
-
|
49
|
+
alert.message = "(point)\n(indexPath)"
|
50
|
+
|
51
|
+
|
52
|
+
|
45
|
-
|
53
|
+
alert.addAction(
|
46
|
-
|
54
|
+
|
47
|
-
|
55
|
+
UIAlertAction(title: "OK", style: .default, handler: nil ))
|
48
|
-
|
56
|
+
|
49
|
-
|
57
|
+
self.present(alert, animated: true, completion: nil)
|
50
|
-
|
51
|
-
|
58
|
+
|
59
|
+
|
52
60
|
|
53
61
|
}
|
54
62
|
|
@@ -60,7 +68,7 @@
|
|
60
68
|
|
61
69
|
上記の方法では`tableView`に設置した`UILongPressGestureRecognizer`でcellとSectionの判別ができないため、コード上でSectionに別途`UILongPressGestureRecognizer`を追加したところ、
|
62
70
|
|
63
|
-
Sectionをロングプレスすると、10%くらいの頻度でCellのロングプレスが反応してしまい正常に機能させることができません。これは実装の仕方に問題があるのでしょうか?
|
71
|
+
Sectionをロングプレスすると、10%くらいの頻度でSectionではなくCellのロングプレスが反応してしまい正常に機能させることができません。これは実装の仕方に問題があるのでしょうか?
|
64
72
|
|
65
73
|
|
66
74
|
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
|
60
60
|
|
61
|
-
`tableView`に設置した`UILongPressGestureRecognizer`でcellとSectionの判別ができないため、コード上でSectionに別途`UILongPressGestureRecognizer`を追加したところ、
|
61
|
+
上記の方法では`tableView`に設置した`UILongPressGestureRecognizer`でcellとSectionの判別ができないため、コード上でSectionに別途`UILongPressGestureRecognizer`を追加したところ、
|
62
62
|
|
63
63
|
Sectionをロングプレスすると、10%くらいの頻度でCellのロングプレスが反応してしまい正常に機能させることができません。これは実装の仕方に問題があるのでしょうか?
|
64
64
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
`tableView`がロングプレスされた際に、gestureの`location`からindexPathが取得できるのですが、Sectionをタップしても、タップしたSection直下のCellのindexpathしか取得できず、indexPathからロングタップされたのがSectionかCellか判別することができません。
|
7
|
+
`tableView`がロングプレスされた際に、gestureの`location`からindexPathが取得できるのですが、Sectionをタップしても、タップしたSection直下のCellのindexpathしか取得できず、indexPathからロングタップされたのがSectionかCellか判別することができません。location、view、subviewsあたりから取得できるcellとsectionを判別する基準があれば教えてください。
|
8
8
|
|
9
9
|
|
10
10
|
|