質問編集履歴

1

修正

2018/04/27 19:12

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -6,6 +6,14 @@
6
6
 
7
7
 
8
8
 
9
+ tableViewのカスタムクラスを作成して、tableViewにタグを付け、touchesBeganをオーバーライドする方向で勧めてみたのですが、
10
+
11
+ カスタムクラス内からViewControllerのプロパティへのアクセス、メソッドを動かすところで詰まっています。
12
+
13
+ カスタムクラス内からviewControllerのプロパティ書き換え、メソッドを呼び出すにはどうすればよいでしょうか?
14
+
15
+
16
+
9
17
  tapRecognizerは他の処理に使用しているので避けたいのですが、tapRecognizerを絡めないと無理でしょうか?
10
18
 
11
19
 
@@ -16,6 +24,70 @@
16
24
 
17
25
  ```swift
18
26
 
27
+ class CustomTableView: UITableView {
28
+
29
+ override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
30
+
31
+ super.touchesBegan(touches, with: event)
32
+
33
+ for touch: UITouch in touches {
34
+
35
+ let tag = touch.view!.tag
36
+
37
+ //let sender = touch.view!
38
+
39
+ switch tag {
40
+
41
+ case 3:
42
+
43
+ let vc = ViewController()
44
+
45
+          // vc = nilなので記述方法が間違っている
46
+
47
+          // 新規にVCを生成してるだけ?
48
+
49
+ print("vc.targetTableView:",vc.targetTableView)
50
+
51
+ vc.targetTableView = true
52
+
53
+ print("vc.targetTableView:",vc.targetTableView)
54
+
55
+ case 4:
56
+
57
+ let vc = ViewController()
58
+
59
+ print("vc.targetTableView:",vc.targetTableView)
60
+
61
+ vc.targetTableView = false
62
+
63
+ print("vc.targetTableView:",vc.targetTableView)
64
+
65
+ default: break
66
+
67
+ }
68
+
69
+ }
70
+
71
+ }
72
+
73
+ }
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ ```
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ ```swift
90
+
19
91
  import UIKit
20
92
 
21
93