回答編集履歴
2
修正
test
CHANGED
@@ -6,4 +6,180 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
追加質問の回答
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
この場合、テーブルがスクロールするたびにaddTargetされているので複数回呼ばれています。
|
16
|
+
|
17
|
+
通常の場合はdelegateを使用して処理するのが一般的だと思うのでそのやり方を以下に載せます。
|
18
|
+
|
9
|
-
|
19
|
+
※追加、削除と書いてあるのが変更した場所です。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
```swift
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
import UIKit
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
class MainViewTableCell: UITableViewCell {
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
@IBOutlet weak var projectNameLabel: UILabel!
|
36
|
+
|
37
|
+
@IBOutlet weak var Btn: UIButton!
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
// ↓ 追加
|
42
|
+
|
43
|
+
weak var delegate: UITableViewCellDelegate!
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
class func nibName() -> String {
|
50
|
+
|
51
|
+
// クラス名と nib 名が同じ前提
|
52
|
+
|
53
|
+
return String(self)
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
class func cellId() -> String {
|
60
|
+
|
61
|
+
return String(self)
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
func setupWith(cellInfo cellInfo_: MainViewCellInfo) {
|
68
|
+
|
69
|
+
self.projectNameLabel.text = cellInfo_.projectName
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
//BtnにIDをセット
|
74
|
+
|
75
|
+
self.Btn.tag = cellInfo_.id
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
// addtargetは削除
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
// ↓ ボタンタップのIBActionを追加
|
86
|
+
|
87
|
+
@IBAction func pushButton(sender: UIButton) {
|
88
|
+
|
89
|
+
delegate.onMessageBtnClick(Btn)
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
// プロトコルの定義を追加
|
98
|
+
|
99
|
+
protocol UITableViewCellDelegate: class {
|
100
|
+
|
101
|
+
func onMessageBtnClick(sender: UIButton)
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
```swift
|
110
|
+
|
111
|
+
import UIKit
|
112
|
+
|
113
|
+
import Alamofire
|
114
|
+
|
115
|
+
import SwiftyJSON
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
// ↓ UITableViewCellDelegateを追加
|
120
|
+
|
121
|
+
class GroupsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITableViewCellDelegate{
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
@IBOutlet weak var TableView: UITableView!
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
override func viewDidLoad() {
|
130
|
+
|
131
|
+
super.viewDidLoad()
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
self.TableView.delegate = self
|
136
|
+
|
137
|
+
self.TableView.dataSource = self
|
138
|
+
|
139
|
+
self.TableView?.rowHeight = 80.0
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
func tableView(TableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
148
|
+
|
149
|
+
print(jsonArray.count)
|
150
|
+
|
151
|
+
return jsonArray.count
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
func tableView(TableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
158
|
+
|
159
|
+
色々書いてます
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
// 以下を追加
|
164
|
+
|
165
|
+
cell.delegate = self;
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
func onMessageBtnClick(sender: UIButton) {
|
172
|
+
|
173
|
+
self.delegate._selectedProjectId = sender.tag
|
174
|
+
|
175
|
+
let storyboard = UIStoryboard(name: "Main", bundle: nil)
|
176
|
+
|
177
|
+
let nextVC = storyboard.instantiateViewControllerWithIdentifier("NextViewController")
|
178
|
+
|
179
|
+
self.navigationController?.pushViewController(nextVC, animated: true)
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
```
|
1
修正
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
TableViewがnilとの事なので、
|
1
|
+
TableViewがnilとの事なので、原因の一つとして遷移する前の部分での生成方法でStoryboardとクラスが紐付いていない事が考えられます。
|
2
2
|
|
3
3
|
|
4
4
|
|