質問編集履歴
2
コードを直しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -114,134 +114,134 @@
|
|
114
114
|
|
115
115
|
|
116
116
|
|
117
|
+
```
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
```
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
class SampleTableview: UITableView, UITableViewDelegate, UITableViewDataSource {
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
var array:[Dictionary<String,String>]!
|
130
|
+
|
131
|
+
var selectedLabel: String?
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
init(frame: CGRect, array:[Dictionary<String,String>]) {
|
138
|
+
|
139
|
+
super.init(frame: frame, style: UITableView.Style.plain)
|
140
|
+
|
141
|
+
self.delegate = self
|
142
|
+
|
143
|
+
self.dataSource = self
|
144
|
+
|
145
|
+
self.frame = frame
|
146
|
+
|
147
|
+
self.array = array
|
148
|
+
|
149
|
+
self.register(UINib(nibName: "CustomTableViewCell", bundle: nil),forCellReuseIdentifier:"CustomCell")
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
required init?(coder: NSCoder) {
|
160
|
+
|
161
|
+
fatalError("init(coder:) has not been implemented")
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
117
167
|
|
118
168
|
|
119
|
-
|
169
|
+
//セルの中身
|
170
|
+
|
120
|
-
|
171
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
121
|
-
""
|
177
|
+
let nextcell = tableView.dequeueReusableCell(withIdentifier: "CustomCell") as! CustomTableViewCell
|
178
|
+
|
122
|
-
|
179
|
+
nextcell.Name.text = self.array[indexPath.row]["name"]
|
180
|
+
|
123
|
-
|
181
|
+
nextcell.Address.text = self.array[indexPath.row]["address"]
|
182
|
+
|
124
|
-
|
183
|
+
//image_urlをURLに変えてそれをData型に変えてそれをUIImage型に変えてからnextcellのimageに代入している
|
184
|
+
|
185
|
+
let url = URL(string: self.array[indexPath.row]["image_url"]!)
|
186
|
+
|
187
|
+
do {
|
188
|
+
|
189
|
+
let data = try Data(contentsOf: url!)
|
190
|
+
|
191
|
+
let image_data = UIImage(data: data)!
|
192
|
+
|
193
|
+
nextcell.RamenImage.image = image_data as? UIImage
|
194
|
+
|
195
|
+
} catch let err {
|
196
|
+
|
197
|
+
print("Error : (err.localizedDescription)")
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
return nextcell
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
//セルが選択された時
|
210
|
+
|
125
|
-
c
|
211
|
+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
var array:[Dictionary<String,String>]!
|
130
|
-
|
131
|
-
var selectedLabel: String?
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
init(frame: CGRect, array:[Dictionary<String,String>]) {
|
138
|
-
|
139
|
-
super.init(frame: frame, style: UITableView.Style.plain)
|
140
|
-
|
141
|
-
self.delegate = self
|
142
|
-
|
143
|
-
self.dataSource = self
|
144
|
-
|
145
|
-
self.frame = frame
|
146
|
-
|
147
|
-
self.array = array
|
148
|
-
|
149
|
-
self.register(UINib(nibName: "CustomTableViewCell", bundle: nil),forCellReuseIdentifier:"CustomCell")
|
150
212
|
|
151
213
|
|
152
214
|
|
215
|
+
let vc = ViewController()
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
vc.performSegue(withIdentifier: "toSubViewController",sender:(self.array[indexPath.row]) )
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
// performSegue(withIdentifier: "toSubViewController",sender:(Name,Address,RamenImage) )
|
224
|
+
|
225
|
+
|
226
|
+
|
153
|
-
}
|
227
|
+
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
159
|
-
|
233
|
+
func tableView(_ tableView: UITableView,
|
160
|
-
|
234
|
+
|
161
|
-
|
235
|
+
heightForRowAt indexPath: IndexPath) -> CGFloat {
|
236
|
+
|
162
|
-
|
237
|
+
return 120.0
|
238
|
+
|
163
|
-
}
|
239
|
+
}
|
164
|
-
|
165
|
-
|
240
|
+
|
241
|
+
|
166
242
|
|
167
243
|
|
168
244
|
|
169
|
-
//セルの中身
|
170
|
-
|
171
|
-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
let nextcell = tableView.dequeueReusableCell(withIdentifier: "CustomCell") as! CustomTableViewCell
|
178
|
-
|
179
|
-
nextcell.Name.text = self.array[indexPath.row]["name"]
|
180
|
-
|
181
|
-
nextcell.Address.text = self.array[indexPath.row]["address"]
|
182
|
-
|
183
|
-
//image_urlをURLに変えてそれをData型に変えてそれをUIImage型に変えてからnextcellのimageに代入している
|
184
|
-
|
185
|
-
let url = URL(string: self.array[indexPath.row]["image_url"]!)
|
186
|
-
|
187
|
-
do {
|
188
|
-
|
189
|
-
let data = try Data(contentsOf: url!)
|
190
|
-
|
191
|
-
let image_data = UIImage(data: data)!
|
192
|
-
|
193
|
-
nextcell.RamenImage.image = image_data as? UIImage
|
194
|
-
|
195
|
-
} catch let err {
|
196
|
-
|
197
|
-
print("Error : (err.localizedDescription)")
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
return nextcell
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
}
|
208
|
-
|
209
|
-
//セルが選択された時
|
210
|
-
|
211
|
-
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
let vc = ViewController()
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
vc.performSegue(withIdentifier: "toSubViewController",sender:(self.array[indexPath.row]) )
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
// performSegue(withIdentifier: "toSubViewController",sender:(Name,Address,RamenImage) )
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
func tableView(_ tableView: UITableView,
|
234
|
-
|
235
|
-
heightForRowAt indexPath: IndexPath) -> CGFloat {
|
236
|
-
|
237
|
-
return 120.0
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
245
|
```
|
246
246
|
|
247
247
|
|
1
コードを直しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,6 +26,8 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
+
```
|
30
|
+
|
29
31
|
`Swift UIKit
|
30
32
|
|
31
33
|
class ViewController: UIViewController, UIScrollViewDelegate,UISearchBarDelegate {
|
@@ -94,27 +96,7 @@
|
|
94
96
|
|
95
97
|
}
|
96
98
|
|
97
|
-
|
99
|
+
|
98
|
-
|
99
|
-
// if (segue.identifier == "SubViewController") {
|
100
|
-
|
101
|
-
//
|
102
|
-
|
103
|
-
//
|
104
|
-
|
105
|
-
// let subVC: SubViewController = (segue.destination as? SubViewController)!
|
106
|
-
|
107
|
-
// let data:(selectedImage: UIImage,outputValue: String) = sender as! (UIImage,String)
|
108
|
-
|
109
|
-
// // SubViewController のselectedImgに選択された画像を設定する
|
110
|
-
|
111
|
-
// subVC.selectedImg = data.selectedImage
|
112
|
-
|
113
|
-
// subVC.outputValue = data.outputValue
|
114
|
-
|
115
|
-
// }
|
116
|
-
|
117
|
-
// }
|
118
100
|
|
119
101
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
120
102
|
|
@@ -132,33 +114,7 @@
|
|
132
114
|
|
133
115
|
|
134
116
|
|
135
|
-
|
117
|
+
|
136
|
-
|
137
|
-
super.viewDidLayoutSubviews()
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
@IBAction func test(_ sender: Any) {
|
148
|
-
|
149
|
-
self.scroll_view.scroll("醤油")
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
154
|
-
|
155
|
-
print("スクロール開始")
|
156
|
-
|
157
|
-
print(scrollView.subviews.first)
|
158
|
-
|
159
|
-
print(scrollView.subviews.first?.frame)
|
160
|
-
|
161
|
-
}
|
162
118
|
|
163
119
|
|
164
120
|
|
@@ -208,11 +164,7 @@
|
|
208
164
|
|
209
165
|
|
210
166
|
|
211
|
-
|
167
|
+
|
212
|
-
|
213
|
-
return self.array.count
|
214
|
-
|
215
|
-
}
|
216
168
|
|
217
169
|
//セルの中身
|
218
170
|
|