質問編集履歴
5
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -300,8 +300,6 @@
|
|
300
300
|
|
301
301
|
var presenter: QuestionListViewPresenter!
|
302
302
|
|
303
|
-
var itemInfo: IndicatorInfo = "新着"
|
304
|
-
|
305
303
|
|
306
304
|
|
307
305
|
override func viewDidLoad() {
|
4
文字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -268,268 +268,138 @@
|
|
268
268
|
|
269
269
|
```
|
270
270
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
var
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
271
|
+
|
272
|
+
|
273
|
+
```NewArrivalQuestionListViewController
|
274
|
+
|
275
|
+
protocol ListViewInterface: class {
|
276
|
+
|
277
|
+
func reloadData()
|
278
|
+
|
279
|
+
func navigateDetail(entity: QuestionEntity)
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
protocol LikeInterface: class {
|
286
|
+
|
287
|
+
var questionId: Int { get }
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
class NewArrivalQuestionListViewController: UIViewController, ListViewInterface {
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
@IBOutlet weak var newArrivalQuestionListTableView: UITableView!
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
var presenter: QuestionListViewPresenter!
|
302
|
+
|
303
|
+
var itemInfo: IndicatorInfo = "新着"
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
override func viewDidLoad() {
|
308
|
+
|
309
|
+
super.viewDidLoad()
|
310
|
+
|
311
|
+
initializePresenter()
|
312
|
+
|
313
|
+
initializeTableView()
|
314
|
+
|
315
|
+
newArrivalQuestionListTableView.refreshControl = UIRefreshControl()
|
316
|
+
|
317
|
+
newArrivalQuestionListTableView.refreshControl?.addTarget(self, action: #selector(self.updateQuestions), for: .valueChanged)
|
318
|
+
|
319
|
+
print("didload")
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
override func viewWillAppear(_ animated: Bool) {
|
326
|
+
|
327
|
+
super.viewWillAppear(true)
|
328
|
+
|
329
|
+
updateQuestions()
|
330
|
+
|
331
|
+
print("willappear")
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
func initializeTableView() {
|
340
|
+
|
341
|
+
newArrivalQuestionListTableView.delegate = self
|
342
|
+
|
343
|
+
newArrivalQuestionListTableView.dataSource = self
|
344
|
+
|
345
|
+
newArrivalQuestionListTableView.register(UINib(nibName: "QuestionListTableViewCell", bundle: nil), forCellReuseIdentifier: "QuestionListTableViewCell")
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
func initializePresenter() {
|
352
|
+
|
353
|
+
presenter = QuestionListViewPresenter(view: self)
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
func reloadData() {
|
360
|
+
|
361
|
+
newArrivalQuestionListTableView.refreshControl?.endRefreshing()
|
362
|
+
|
363
|
+
newArrivalQuestionListTableView.reloadData()
|
364
|
+
|
365
|
+
print("リロード")
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
func navigateDetail(entity: QuestionEntity) {
|
372
|
+
|
373
|
+
let questoinDetailViewController = QuestionDetailViewController(entity: entity)
|
374
|
+
|
375
|
+
self.navigationController?.pushViewController(questoinDetailViewController, animated: true)
|
376
|
+
|
377
|
+
}
|
304
378
|
|
305
379
|
|
306
380
|
|
307
381
|
@objc func updateQuestions() {
|
308
382
|
|
309
|
-
|
383
|
+
presenter.updateQuestions()
|
310
|
-
|
384
|
+
|
311
|
-
|
385
|
+
newArrivalQuestionListTableView.refreshControl?.beginRefreshing()
|
312
|
-
|
386
|
+
|
313
|
-
}
|
387
|
+
}
|
314
|
-
|
315
|
-
|
316
|
-
|
388
|
+
|
389
|
+
|
390
|
+
|
317
|
-
func e
|
391
|
+
@objc func likeButtonTapped(_ sender: UIButton, forEvent event: UIEvent) {
|
392
|
+
|
318
|
-
|
393
|
+
let touch = event.allTouches?.first
|
394
|
+
|
319
|
-
|
395
|
+
let point = touch!.location(in: self.newArrivalQuestionListTableView)
|
320
|
-
|
321
|
-
|
396
|
+
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
func didSelectRow(at indexPath: IndexPath) {
|
326
|
-
|
327
|
-
|
397
|
+
let indexPath = newArrivalQuestionListTableView.indexPathForRow(at: point)!
|
328
|
-
|
329
|
-
|
398
|
+
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
@objc func updated() {
|
334
|
-
|
335
|
-
view?.reloadData()
|
336
|
-
|
337
|
-
}
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
399
|
+
presenter.likeButtonTapped(at: indexPath)
|
342
|
-
|
343
|
-
likeModel.updateLikesData(id: questionModel.questions[indexPath.row].id)
|
344
400
|
|
345
401
|
}
|
346
402
|
|
347
403
|
}
|
348
404
|
|
349
405
|
```
|
350
|
-
|
351
|
-
```NewArrivalQuestionListViewController
|
352
|
-
|
353
|
-
protocol ListViewInterface: class {
|
354
|
-
|
355
|
-
func reloadData()
|
356
|
-
|
357
|
-
func navigateDetail(entity: QuestionEntity)
|
358
|
-
|
359
|
-
}
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
protocol LikeInterface: class {
|
364
|
-
|
365
|
-
var questionId: Int { get }
|
366
|
-
|
367
|
-
}
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
class NewArrivalQuestionListViewController: UIViewController, ListViewInterface {
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
@IBOutlet weak var newArrivalQuestionListTableView: UITableView!
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
var presenter: QuestionListViewPresenter!
|
380
|
-
|
381
|
-
var itemInfo: IndicatorInfo = "新着"
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
override func viewDidLoad() {
|
386
|
-
|
387
|
-
super.viewDidLoad()
|
388
|
-
|
389
|
-
initializePresenter()
|
390
|
-
|
391
|
-
initializeTableView()
|
392
|
-
|
393
|
-
newArrivalQuestionListTableView.refreshControl = UIRefreshControl()
|
394
|
-
|
395
|
-
newArrivalQuestionListTableView.refreshControl?.addTarget(self, action: #selector(self.updateQuestions), for: .valueChanged)
|
396
|
-
|
397
|
-
print("didload")
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
override func viewWillAppear(_ animated: Bool) {
|
404
|
-
|
405
|
-
super.viewWillAppear(true)
|
406
|
-
|
407
|
-
updateQuestions()
|
408
|
-
|
409
|
-
print("willappear")
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
}
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
func initializeTableView() {
|
418
|
-
|
419
|
-
newArrivalQuestionListTableView.delegate = self
|
420
|
-
|
421
|
-
newArrivalQuestionListTableView.dataSource = self
|
422
|
-
|
423
|
-
newArrivalQuestionListTableView.register(UINib(nibName: "QuestionListTableViewCell", bundle: nil), forCellReuseIdentifier: "QuestionListTableViewCell")
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
func initializePresenter() {
|
430
|
-
|
431
|
-
presenter = QuestionListViewPresenter(view: self)
|
432
|
-
|
433
|
-
}
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
func reloadData() {
|
438
|
-
|
439
|
-
newArrivalQuestionListTableView.refreshControl?.endRefreshing()
|
440
|
-
|
441
|
-
newArrivalQuestionListTableView.reloadData()
|
442
|
-
|
443
|
-
print("リロード")
|
444
|
-
|
445
|
-
}
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
func navigateDetail(entity: QuestionEntity) {
|
450
|
-
|
451
|
-
let questoinDetailViewController = QuestionDetailViewController(entity: entity)
|
452
|
-
|
453
|
-
self.navigationController?.pushViewController(questoinDetailViewController, animated: true)
|
454
|
-
|
455
|
-
}
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
@objc func updateQuestions() {
|
460
|
-
|
461
|
-
presenter.updateQuestions()
|
462
|
-
|
463
|
-
newArrivalQuestionListTableView.refreshControl?.beginRefreshing()
|
464
|
-
|
465
|
-
}
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
@objc func likeButtonTapped(_ sender: UIButton, forEvent event: UIEvent) {
|
470
|
-
|
471
|
-
let touch = event.allTouches?.first
|
472
|
-
|
473
|
-
let point = touch!.location(in: self.newArrivalQuestionListTableView)
|
474
|
-
|
475
|
-
let indexPath = newArrivalQuestionListTableView.indexPathForRow(at: point)!
|
476
|
-
|
477
|
-
presenter.likeButtonTapped(at: indexPath)
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
}
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
extension NewArrivalQuestionListViewController: UITableViewDelegate, UITableViewDataSource {
|
488
|
-
|
489
|
-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
490
|
-
|
491
|
-
return presenter.numberOfQuestions
|
492
|
-
|
493
|
-
}
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
498
|
-
|
499
|
-
let cell = newArrivalQuestionListTableView.dequeueReusableCell(withIdentifier: "QuestionListTableViewCell", for: indexPath) as! QuestionListTableViewCell
|
500
|
-
|
501
|
-
cell.setQuestion(entity: presenter.entity(at: indexPath))
|
502
|
-
|
503
|
-
cell.likeButton.addTarget(self, action: #selector(likeButtonTapped(_:forEvent:)), for: .touchUpInside)
|
504
|
-
|
505
|
-
return cell
|
506
|
-
|
507
|
-
}
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
512
|
-
|
513
|
-
newArrivalQuestionListTableView.deselectRow(at: indexPath, animated: true)
|
514
|
-
|
515
|
-
presenter.didSelectRow(at: indexPath)
|
516
|
-
|
517
|
-
}
|
518
|
-
|
519
|
-
}
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
extension NewArrivalQuestionListViewController: IndicatorInfoProvider {
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
|
528
|
-
|
529
|
-
return itemInfo
|
530
|
-
|
531
|
-
}
|
532
|
-
|
533
|
-
}
|
534
|
-
|
535
|
-
```
|
3
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,406 +130,406 @@
|
|
130
130
|
|
131
131
|
```
|
132
132
|
|
133
|
+
```QuestionModel
|
134
|
+
|
135
|
+
class QuestionModel {
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
var questions: [QuestionEntity] = []
|
140
|
+
|
141
|
+
var notificationName: Notification.Name {
|
142
|
+
|
143
|
+
return Notification.Name(rawValue: "questions")
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
func fetchNewArivalQuestions() {
|
150
|
+
|
151
|
+
print("fetch")
|
152
|
+
|
153
|
+
Alamofire.request("https://teratail.com/api/v1/questions").responseJSON { response in
|
154
|
+
|
155
|
+
self.questions = []
|
156
|
+
|
157
|
+
guard let object = response.result.value else { return }
|
158
|
+
|
159
|
+
let json = JSON(object)
|
160
|
+
|
161
|
+
json["questions"].forEach { (_, json) in
|
162
|
+
|
163
|
+
let id = json["id"].intValue
|
164
|
+
|
165
|
+
let title = json["title"].stringValue
|
166
|
+
|
167
|
+
let tags = json["tags"].arrayObject
|
168
|
+
|
169
|
+
let displayName = json["user"]["display_name"].stringValue
|
170
|
+
|
171
|
+
let photo = json["user"]["photo"].stringValue
|
172
|
+
|
173
|
+
let created = json["created"].stringValue
|
174
|
+
|
175
|
+
let isAccepted = json["is_accepted"].boolValue
|
176
|
+
|
177
|
+
self.questions.append(QuestionEntity(id: id, title: title, tags: tags as! [String], displayName: displayName, photo: photo, created: created, isAccepted: isAccepted))
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
self.notify()
|
182
|
+
|
183
|
+
print("通知")
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
func addObserver(_ observer: Any, selector: Selector) {
|
192
|
+
|
193
|
+
NotificationCenter.default.addObserver(observer, selector: selector, name: notificationName, object: nil)
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
func removeObserver(_ observer: Any) {
|
200
|
+
|
201
|
+
NotificationCenter.default.removeObserver(observer)
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
func notify() {
|
208
|
+
|
209
|
+
NotificationCenter.default.post(name: notificationName, object: nil)
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
}
|
216
|
+
|
133
217
|
```
|
134
218
|
|
219
|
+
|
220
|
+
|
135
|
-
|
221
|
+
```QuestionListTableViewCell
|
222
|
+
|
136
|
-
|
223
|
+
class QuestionListTableViewCell: UITableViewCell {
|
224
|
+
|
225
|
+
|
226
|
+
|
137
|
-
|
227
|
+
@IBOutlet weak var photoImageView: UIImageView!
|
228
|
+
|
138
|
-
|
229
|
+
@IBOutlet weak var displayNameLabel: UILabel!
|
230
|
+
|
231
|
+
@IBOutlet weak var createdLabel: UILabel!
|
232
|
+
|
233
|
+
@IBOutlet weak var titleLabel: UILabel!
|
234
|
+
|
235
|
+
@IBOutlet weak var likeButton: UIButton!
|
236
|
+
|
237
|
+
@IBOutlet weak var tagsLabel: UILabel!
|
238
|
+
|
239
|
+
@IBOutlet weak var isAcceptedLabel: UILabel!
|
240
|
+
|
241
|
+
|
242
|
+
|
139
|
-
|
243
|
+
func setQuestion(entity: QuestionEntity) {
|
140
|
-
|
244
|
+
|
141
|
-
|
245
|
+
self.displayNameLabel.text = entity.displayName
|
246
|
+
|
247
|
+
|
248
|
+
|
142
|
-
|
249
|
+
// Likeボタンの表示
|
250
|
+
|
251
|
+
if entity.isLiked == true {
|
252
|
+
|
253
|
+
likeButton.setImage(UIImage(systemName: "star.fill"), for: .normal)
|
254
|
+
|
255
|
+
print("starfill")
|
256
|
+
|
257
|
+
} else {
|
258
|
+
|
143
|
-
|
259
|
+
likeButton.setImage(UIImage(systemName: "star"), for: .normal)
|
144
|
-
|
145
|
-
|
260
|
+
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
func fetchNewArivalQuestions() {
|
150
|
-
|
151
|
-
print("
|
261
|
+
print("star")
|
152
|
-
|
153
|
-
Alamofire.request("https://teratail.com/api/v1/questions").responseJSON { response in
|
154
|
-
|
155
|
-
self.questions = []
|
156
|
-
|
157
|
-
guard let object = response.result.value else { return }
|
158
|
-
|
159
|
-
let json = JSON(object)
|
160
|
-
|
161
|
-
json["questions"].forEach { (_, json) in
|
162
|
-
|
163
|
-
let id = json["id"].intValue
|
164
|
-
|
165
|
-
let title = json["title"].stringValue
|
166
|
-
|
167
|
-
let tags = json["tags"].arrayObject
|
168
|
-
|
169
|
-
let displayName = json["user"]["display_name"].stringValue
|
170
|
-
|
171
|
-
let photo = json["user"]["photo"].stringValue
|
172
|
-
|
173
|
-
let created = json["created"].stringValue
|
174
|
-
|
175
|
-
let isAccepted = json["is_accepted"].boolValue
|
176
|
-
|
177
|
-
self.questions.append(QuestionEntity(id: id, title: title, tags: tags as! [String], displayName: displayName, photo: photo, created: created, isAccepted: isAccepted))
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
self.notify()
|
182
|
-
|
183
|
-
print("通知")
|
184
262
|
|
185
263
|
}
|
186
264
|
|
187
265
|
}
|
188
266
|
|
189
|
-
|
190
|
-
|
191
|
-
func addObserver(_ observer: Any, selector: Selector) {
|
192
|
-
|
193
|
-
NotificationCenter.default.addObserver(observer, selector: selector, name: notificationName, object: nil)
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
func removeObserver(_ observer: Any) {
|
200
|
-
|
201
|
-
NotificationCenter.default.removeObserver(observer)
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
func notify() {
|
208
|
-
|
209
|
-
NotificationCenter.default.post(name: notificationName, object: nil)
|
210
|
-
|
211
|
-
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
267
|
}
|
216
268
|
|
217
269
|
```
|
218
270
|
|
219
|
-
|
220
|
-
|
221
|
-
```QuestionList
|
271
|
+
```QuestionListViewPresenter
|
222
|
-
|
272
|
+
|
223
|
-
class QuestionList
|
273
|
+
class QuestionListViewPresenter {
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
private weak var view: ListViewInterface!
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
var questionModel: QuestionModel!
|
282
|
+
|
283
|
+
var likeModel = LikeModel()
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
var numberOfQuestions: Int {
|
288
|
+
|
289
|
+
return questionModel?.questions.count ?? 10
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
init(view: ListViewInterface) {
|
296
|
+
|
297
|
+
self.view = view
|
298
|
+
|
299
|
+
self.questionModel = QuestionModel()
|
300
|
+
|
301
|
+
self.questionModel.addObserver(self, selector: #selector(self.updated))
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
@objc func updateQuestions() {
|
308
|
+
|
309
|
+
questionModel.fetchNewArivalQuestions()
|
310
|
+
|
311
|
+
print("presenter")
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
func entity(at indexPath: IndexPath) -> QuestionEntity {
|
318
|
+
|
319
|
+
return questionModel.questions[indexPath.row]
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
func didSelectRow(at indexPath: IndexPath) {
|
326
|
+
|
327
|
+
view?.navigateDetail(entity: questionModel.questions[indexPath.row])
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
@objc func updated() {
|
334
|
+
|
335
|
+
view?.reloadData()
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
func likeButtonTapped(at indexPath: IndexPath) {
|
342
|
+
|
343
|
+
likeModel.updateLikesData(id: questionModel.questions[indexPath.row].id)
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
```
|
350
|
+
|
351
|
+
```NewArrivalQuestionListViewController
|
352
|
+
|
353
|
+
protocol ListViewInterface: class {
|
354
|
+
|
355
|
+
func reloadData()
|
356
|
+
|
357
|
+
func navigateDetail(entity: QuestionEntity)
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
protocol LikeInterface: class {
|
364
|
+
|
365
|
+
var questionId: Int { get }
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
class NewArrivalQuestionListViewController: UIViewController, ListViewInterface {
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
@IBOutlet weak var newArrivalQuestionListTableView: UITableView!
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
var presenter: QuestionListViewPresenter!
|
380
|
+
|
381
|
+
var itemInfo: IndicatorInfo = "新着"
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
override func viewDidLoad() {
|
386
|
+
|
387
|
+
super.viewDidLoad()
|
388
|
+
|
389
|
+
initializePresenter()
|
390
|
+
|
391
|
+
initializeTableView()
|
392
|
+
|
393
|
+
newArrivalQuestionListTableView.refreshControl = UIRefreshControl()
|
394
|
+
|
395
|
+
newArrivalQuestionListTableView.refreshControl?.addTarget(self, action: #selector(self.updateQuestions), for: .valueChanged)
|
396
|
+
|
397
|
+
print("didload")
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
override func viewWillAppear(_ animated: Bool) {
|
404
|
+
|
405
|
+
super.viewWillAppear(true)
|
406
|
+
|
407
|
+
updateQuestions()
|
408
|
+
|
409
|
+
print("willappear")
|
224
410
|
|
225
411
|
|
226
412
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
func
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
413
|
+
}
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
func initializeTableView() {
|
418
|
+
|
419
|
+
newArrivalQuestionListTableView.delegate = self
|
420
|
+
|
421
|
+
newArrivalQuestionListTableView.dataSource = self
|
422
|
+
|
423
|
+
newArrivalQuestionListTableView.register(UINib(nibName: "QuestionListTableViewCell", bundle: nil), forCellReuseIdentifier: "QuestionListTableViewCell")
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
func initializePresenter() {
|
430
|
+
|
431
|
+
presenter = QuestionListViewPresenter(view: self)
|
432
|
+
|
433
|
+
}
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
func reloadData() {
|
438
|
+
|
439
|
+
newArrivalQuestionListTableView.refreshControl?.endRefreshing()
|
440
|
+
|
441
|
+
newArrivalQuestionListTableView.reloadData()
|
442
|
+
|
443
|
+
print("リロード")
|
444
|
+
|
445
|
+
}
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
func navigateDetail(entity: QuestionEntity) {
|
450
|
+
|
451
|
+
let questoinDetailViewController = QuestionDetailViewController(entity: entity)
|
452
|
+
|
453
|
+
self.navigationController?.pushViewController(questoinDetailViewController, animated: true)
|
454
|
+
|
455
|
+
}
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
@objc func updateQuestions() {
|
460
|
+
|
461
|
+
presenter.updateQuestions()
|
462
|
+
|
463
|
+
newArrivalQuestionListTableView.refreshControl?.beginRefreshing()
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
@objc func likeButtonTapped(_ sender: UIButton, forEvent event: UIEvent) {
|
470
|
+
|
471
|
+
let touch = event.allTouches?.first
|
472
|
+
|
473
|
+
let point = touch!.location(in: self.newArrivalQuestionListTableView)
|
474
|
+
|
475
|
+
let indexPath = newArrivalQuestionListTableView.indexPathForRow(at: point)!
|
476
|
+
|
477
|
+
presenter.likeButtonTapped(at: indexPath)
|
478
|
+
|
479
|
+
}
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
}
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
extension NewArrivalQuestionListViewController: UITableViewDelegate, UITableViewDataSource {
|
488
|
+
|
489
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
490
|
+
|
491
|
+
return presenter.numberOfQuestions
|
492
|
+
|
493
|
+
}
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
498
|
+
|
499
|
+
let cell = newArrivalQuestionListTableView.dequeueReusableCell(withIdentifier: "QuestionListTableViewCell", for: indexPath) as! QuestionListTableViewCell
|
500
|
+
|
501
|
+
cell.setQuestion(entity: presenter.entity(at: indexPath))
|
502
|
+
|
503
|
+
cell.likeButton.addTarget(self, action: #selector(likeButtonTapped(_:forEvent:)), for: .touchUpInside)
|
504
|
+
|
505
|
+
return cell
|
506
|
+
|
507
|
+
}
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
512
|
+
|
513
|
+
newArrivalQuestionListTableView.deselectRow(at: indexPath, animated: true)
|
514
|
+
|
515
|
+
presenter.didSelectRow(at: indexPath)
|
516
|
+
|
517
|
+
}
|
518
|
+
|
519
|
+
}
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
extension NewArrivalQuestionListViewController: IndicatorInfoProvider {
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
|
528
|
+
|
529
|
+
return itemInfo
|
262
530
|
|
263
531
|
}
|
264
532
|
|
265
|
-
}
|
266
|
-
|
267
533
|
}
|
268
534
|
|
269
535
|
```
|
270
|
-
|
271
|
-
```QuestionListViewPresenter
|
272
|
-
|
273
|
-
class QuestionListViewPresenter {
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
private weak var view: ListViewInterface!
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
var questionModel: QuestionModel!
|
282
|
-
|
283
|
-
var likeModel = LikeModel()
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
var numberOfQuestions: Int {
|
288
|
-
|
289
|
-
return questionModel?.questions.count ?? 10
|
290
|
-
|
291
|
-
}
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
init(view: ListViewInterface) {
|
296
|
-
|
297
|
-
self.view = view
|
298
|
-
|
299
|
-
self.questionModel = QuestionModel()
|
300
|
-
|
301
|
-
self.questionModel.addObserver(self, selector: #selector(self.updated))
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
@objc func updateQuestions() {
|
308
|
-
|
309
|
-
questionModel.fetchNewArivalQuestions()
|
310
|
-
|
311
|
-
print("presenter")
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
func entity(at indexPath: IndexPath) -> QuestionEntity {
|
318
|
-
|
319
|
-
return questionModel.questions[indexPath.row]
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
func didSelectRow(at indexPath: IndexPath) {
|
326
|
-
|
327
|
-
view?.navigateDetail(entity: questionModel.questions[indexPath.row])
|
328
|
-
|
329
|
-
}
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
@objc func updated() {
|
334
|
-
|
335
|
-
view?.reloadData()
|
336
|
-
|
337
|
-
}
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
func likeButtonTapped(at indexPath: IndexPath) {
|
342
|
-
|
343
|
-
likeModel.updateLikesData(id: questionModel.questions[indexPath.row].id)
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
}
|
348
|
-
|
349
|
-
```
|
350
|
-
|
351
|
-
```NewArrivalQuestionListViewController
|
352
|
-
|
353
|
-
protocol ListViewInterface: class {
|
354
|
-
|
355
|
-
func reloadData()
|
356
|
-
|
357
|
-
func navigateDetail(entity: QuestionEntity)
|
358
|
-
|
359
|
-
}
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
protocol LikeInterface: class {
|
364
|
-
|
365
|
-
var questionId: Int { get }
|
366
|
-
|
367
|
-
}
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
class NewArrivalQuestionListViewController: UIViewController, ListViewInterface {
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
@IBOutlet weak var newArrivalQuestionListTableView: UITableView!
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
var presenter: QuestionListViewPresenter!
|
380
|
-
|
381
|
-
var itemInfo: IndicatorInfo = "新着"
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
override func viewDidLoad() {
|
386
|
-
|
387
|
-
super.viewDidLoad()
|
388
|
-
|
389
|
-
initializePresenter()
|
390
|
-
|
391
|
-
initializeTableView()
|
392
|
-
|
393
|
-
newArrivalQuestionListTableView.refreshControl = UIRefreshControl()
|
394
|
-
|
395
|
-
newArrivalQuestionListTableView.refreshControl?.addTarget(self, action: #selector(self.updateQuestions), for: .valueChanged)
|
396
|
-
|
397
|
-
print("didload")
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
override func viewWillAppear(_ animated: Bool) {
|
404
|
-
|
405
|
-
super.viewWillAppear(true)
|
406
|
-
|
407
|
-
updateQuestions()
|
408
|
-
|
409
|
-
print("willappear")
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
}
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
func initializeTableView() {
|
418
|
-
|
419
|
-
newArrivalQuestionListTableView.delegate = self
|
420
|
-
|
421
|
-
newArrivalQuestionListTableView.dataSource = self
|
422
|
-
|
423
|
-
newArrivalQuestionListTableView.register(UINib(nibName: "QuestionListTableViewCell", bundle: nil), forCellReuseIdentifier: "QuestionListTableViewCell")
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
func initializePresenter() {
|
430
|
-
|
431
|
-
presenter = QuestionListViewPresenter(view: self)
|
432
|
-
|
433
|
-
}
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
func reloadData() {
|
438
|
-
|
439
|
-
newArrivalQuestionListTableView.refreshControl?.endRefreshing()
|
440
|
-
|
441
|
-
newArrivalQuestionListTableView.reloadData()
|
442
|
-
|
443
|
-
print("リロード")
|
444
|
-
|
445
|
-
}
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
func navigateDetail(entity: QuestionEntity) {
|
450
|
-
|
451
|
-
let questoinDetailViewController = QuestionDetailViewController(entity: entity)
|
452
|
-
|
453
|
-
self.navigationController?.pushViewController(questoinDetailViewController, animated: true)
|
454
|
-
|
455
|
-
}
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
@objc func updateQuestions() {
|
460
|
-
|
461
|
-
presenter.updateQuestions()
|
462
|
-
|
463
|
-
newArrivalQuestionListTableView.refreshControl?.beginRefreshing()
|
464
|
-
|
465
|
-
}
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
@objc func likeButtonTapped(_ sender: UIButton, forEvent event: UIEvent) {
|
470
|
-
|
471
|
-
let touch = event.allTouches?.first
|
472
|
-
|
473
|
-
let point = touch!.location(in: self.newArrivalQuestionListTableView)
|
474
|
-
|
475
|
-
let indexPath = newArrivalQuestionListTableView.indexPathForRow(at: point)!
|
476
|
-
|
477
|
-
presenter.likeButtonTapped(at: indexPath)
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
}
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
extension NewArrivalQuestionListViewController: UITableViewDelegate, UITableViewDataSource {
|
488
|
-
|
489
|
-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
490
|
-
|
491
|
-
return presenter.numberOfQuestions
|
492
|
-
|
493
|
-
}
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
498
|
-
|
499
|
-
let cell = newArrivalQuestionListTableView.dequeueReusableCell(withIdentifier: "QuestionListTableViewCell", for: indexPath) as! QuestionListTableViewCell
|
500
|
-
|
501
|
-
cell.setQuestion(entity: presenter.entity(at: indexPath))
|
502
|
-
|
503
|
-
cell.likeButton.addTarget(self, action: #selector(likeButtonTapped(_:forEvent:)), for: .touchUpInside)
|
504
|
-
|
505
|
-
return cell
|
506
|
-
|
507
|
-
}
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
512
|
-
|
513
|
-
newArrivalQuestionListTableView.deselectRow(at: indexPath, animated: true)
|
514
|
-
|
515
|
-
presenter.didSelectRow(at: indexPath)
|
516
|
-
|
517
|
-
}
|
518
|
-
|
519
|
-
}
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
extension NewArrivalQuestionListViewController: IndicatorInfoProvider {
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
|
528
|
-
|
529
|
-
return itemInfo
|
530
|
-
|
531
|
-
}
|
532
|
-
|
533
|
-
}
|
534
|
-
|
535
|
-
```
|
2
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,6 +130,92 @@
|
|
130
130
|
|
131
131
|
```
|
132
132
|
|
133
|
+
```
|
134
|
+
|
135
|
+
class QuestionModel {
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
var questions: [QuestionEntity] = []
|
140
|
+
|
141
|
+
var notificationName: Notification.Name {
|
142
|
+
|
143
|
+
return Notification.Name(rawValue: "questions")
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
func fetchNewArivalQuestions() {
|
150
|
+
|
151
|
+
print("fetch")
|
152
|
+
|
153
|
+
Alamofire.request("https://teratail.com/api/v1/questions").responseJSON { response in
|
154
|
+
|
155
|
+
self.questions = []
|
156
|
+
|
157
|
+
guard let object = response.result.value else { return }
|
158
|
+
|
159
|
+
let json = JSON(object)
|
160
|
+
|
161
|
+
json["questions"].forEach { (_, json) in
|
162
|
+
|
163
|
+
let id = json["id"].intValue
|
164
|
+
|
165
|
+
let title = json["title"].stringValue
|
166
|
+
|
167
|
+
let tags = json["tags"].arrayObject
|
168
|
+
|
169
|
+
let displayName = json["user"]["display_name"].stringValue
|
170
|
+
|
171
|
+
let photo = json["user"]["photo"].stringValue
|
172
|
+
|
173
|
+
let created = json["created"].stringValue
|
174
|
+
|
175
|
+
let isAccepted = json["is_accepted"].boolValue
|
176
|
+
|
177
|
+
self.questions.append(QuestionEntity(id: id, title: title, tags: tags as! [String], displayName: displayName, photo: photo, created: created, isAccepted: isAccepted))
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
self.notify()
|
182
|
+
|
183
|
+
print("通知")
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
func addObserver(_ observer: Any, selector: Selector) {
|
192
|
+
|
193
|
+
NotificationCenter.default.addObserver(observer, selector: selector, name: notificationName, object: nil)
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
func removeObserver(_ observer: Any) {
|
200
|
+
|
201
|
+
NotificationCenter.default.removeObserver(observer)
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
func notify() {
|
208
|
+
|
209
|
+
NotificationCenter.default.post(name: notificationName, object: nil)
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
```
|
218
|
+
|
133
219
|
|
134
220
|
|
135
221
|
```QuestionListTableViewCell
|
1
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
しかし、`viewDidLoad`、`viewWillAppear`、UIRefershControl実行時にはデフォルトの状態で表示されてしまいます。
|
21
|
+
しかし、`viewDidLoad`、`viewWillAppear`、`UIRefershControl`実行時にはデフォルトの状態で表示されてしまいます。
|
22
22
|
|
23
23
|
つまり、`func updateQuestions()`実行時に問題が発生します。
|
24
24
|
|