質問編集履歴
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,11 +2,47 @@
|
|
2
2
|
cellをタップすると、タップされたcellが存在するTableViewを編集対象にするという処理をしているのですが、
|
3
3
|
tableViewのcellが存在しない余白部分をタップした際に、同じような挙動を得る為に良い方法はないでしょうか?
|
4
4
|
|
5
|
+
tableViewのカスタムクラスを作成して、tableViewにタグを付け、touchesBeganをオーバーライドする方向で勧めてみたのですが、
|
6
|
+
カスタムクラス内からViewControllerのプロパティへのアクセス、メソッドを動かすところで詰まっています。
|
7
|
+
カスタムクラス内からviewControllerのプロパティ書き換え、メソッドを呼び出すにはどうすればよいでしょうか?
|
8
|
+
|
5
9
|
tapRecognizerは他の処理に使用しているので避けたいのですが、tapRecognizerを絡めないと無理でしょうか?
|
6
10
|
|
7
11
|

|
8
12
|
|
9
13
|
```swift
|
14
|
+
class CustomTableView: UITableView {
|
15
|
+
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
16
|
+
super.touchesBegan(touches, with: event)
|
17
|
+
for touch: UITouch in touches {
|
18
|
+
let tag = touch.view!.tag
|
19
|
+
//let sender = touch.view!
|
20
|
+
switch tag {
|
21
|
+
case 3:
|
22
|
+
let vc = ViewController()
|
23
|
+
// vc = nilなので記述方法が間違っている
|
24
|
+
// 新規にVCを生成してるだけ?
|
25
|
+
print("vc.targetTableView:",vc.targetTableView)
|
26
|
+
vc.targetTableView = true
|
27
|
+
print("vc.targetTableView:",vc.targetTableView)
|
28
|
+
case 4:
|
29
|
+
let vc = ViewController()
|
30
|
+
print("vc.targetTableView:",vc.targetTableView)
|
31
|
+
vc.targetTableView = false
|
32
|
+
print("vc.targetTableView:",vc.targetTableView)
|
33
|
+
default: break
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```swift
|
10
46
|
import UIKit
|
11
47
|
|
12
48
|
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|