回答編集履歴
1
コード追記
test
CHANGED
@@ -67,3 +67,147 @@
|
|
67
67
|
}
|
68
68
|
|
69
69
|
```
|
70
|
+
|
71
|
+
---
|
72
|
+
|
73
|
+
コード全文です。
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```Swift
|
78
|
+
|
79
|
+
import UIKit
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
class ViewController: UITableViewController {
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
var parts = [
|
88
|
+
|
89
|
+
["title":"カルビ", "detail":"油がすごい"],
|
90
|
+
|
91
|
+
["title":"レバー", "detail":"内臓です"],
|
92
|
+
|
93
|
+
["title":"ホルモン", "detail":"牛の腸です"],
|
94
|
+
|
95
|
+
["title":"タン", "detail":"牛のベロです"]
|
96
|
+
|
97
|
+
]
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
override func viewDidLoad() {
|
102
|
+
|
103
|
+
super.viewDidLoad()
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
// MARK: - Table view data source
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
override func numberOfSections(in tableView: UITableView) -> Int {
|
116
|
+
|
117
|
+
// #warning Incomplete implementation, return the number of sections
|
118
|
+
|
119
|
+
return 1
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
126
|
+
|
127
|
+
// #warning Incomplete implementation, return the number of rows
|
128
|
+
|
129
|
+
return self.parts.count
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
138
|
+
|
139
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "YakinikuTableViewCell", for: indexPath)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
// Configure the cell...
|
144
|
+
|
145
|
+
cell.textLabel?.text = self.parts[indexPath.row]["title"]
|
146
|
+
|
147
|
+
return cell
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
154
|
+
|
155
|
+
tableView.deselectRow(at: indexPath, animated: true)
|
156
|
+
|
157
|
+
performSegue(withIdentifier: "toDetailVC", sender: parts[indexPath.row])
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
164
|
+
|
165
|
+
let detailVC = segue.destination as! DetailViewController
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
// Any? 型として渡されているので、[String: String] に変換する
|
170
|
+
|
171
|
+
if let selectedParts = sender as? [String : String] {
|
172
|
+
|
173
|
+
detailVC.selectedParts = selectedParts
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
```
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
```Swift
|
186
|
+
|
187
|
+
import UIKit
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
class DetailViewController: UIViewController {
|
192
|
+
|
193
|
+
@IBOutlet weak var partNameLabel: UILabel!
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
var selectedParts: [String: String]!
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
override func viewDidLoad() {
|
202
|
+
|
203
|
+
super.viewDidLoad()
|
204
|
+
|
205
|
+
partNameLabel.text = selectedParts["title"]
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
```
|