質問編集履歴

1

マークダウン形式に変更して、ソースを抜粋

2018/03/19 11:14

投稿

akiraa
akiraa

スコア11

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,7 @@
1
+ ### 前提・実現したいこと
2
+
3
+
4
+
1
5
  下記のようなTableViewを作成しています
2
6
 
3
7
  表示上はセルを追加されたように見えてもindexPathが増加していないため
@@ -8,6 +12,22 @@
8
12
 
9
13
 
10
14
 
15
+ ### 発生している問題・エラーメッセージ
16
+
17
+ ```
18
+
19
+ セルをタップしても、該当のIndexPathが取得できない
20
+
21
+ ```
22
+
23
+
24
+
25
+ ### 該当のソースコード
26
+
27
+
28
+
29
+ ```Swift
30
+
11
31
  import UIKit
12
32
 
13
33
  import AVFoundation
@@ -216,37 +236,13 @@
216
236
 
217
237
  }
218
238
 
219
-
220
-
239
+
240
+
221
- let codeLabel:UILabel = {
241
+ override func viewWillAppear(_ animated: Bool) {
222
-
242
+
223
- let codeLabel = UILabel()
243
+ self.tableView.reloadData()
224
-
225
- codeLabel.backgroundColor = .white
244
+
226
-
227
- codeLabel.translatesAutoresizingMaskIntoConstraints = false
228
-
229
- return codeLabel
230
-
231
- }()
245
+ }
232
-
233
-
234
-
235
- let codeFrame:UIView = {
236
-
237
- let codeFrame = UIView()
238
-
239
- codeFrame.layer.borderColor = UIColor.green.cgColor
240
-
241
- codeFrame.layer.borderWidth = 2
242
-
243
- codeFrame.frame = CGRect.zero
244
-
245
- codeFrame.translatesAutoresizingMaskIntoConstraints = false
246
-
247
- return codeFrame
248
-
249
- }()
250
246
 
251
247
 
252
248
 
@@ -290,16 +286,10 @@
290
286
 
291
287
  self.tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: UITableViewRowAnimation.right)
292
288
 
293
- view.addSubview(codeFrame)
294
-
295
289
 
296
290
 
297
291
  guard let barcodeObject = videoPreviewLayer?.transformedMetadataObject(for: metadataObject) else { return }
298
292
 
299
- codeFrame.frame = barcodeObject.bounds
300
-
301
- codeLabel.text = stringCodeValue
302
-
303
293
 
304
294
 
305
295
  // Play system sound with custom mp3 file
@@ -346,22 +336,6 @@
346
336
 
347
337
 
348
338
 
349
- func displayDetailsViewController(scannedCode: String) {
350
-
351
-
352
-
353
- let detailsViewController = DetailsViewController()
354
-
355
- detailsViewController.scannedCode = scannedCode
356
-
357
- //navigationController?.pushViewController(detailsViewController, animated: true)
358
-
359
- present(detailsViewController, animated: true, completion: nil)
360
-
361
- }
362
-
363
-
364
-
365
339
  @objc func update(tm: Timer) {
366
340
 
367
341
  counter += 1
@@ -396,7 +370,7 @@
396
370
 
397
371
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
398
372
 
399
-
373
+ print("items.count (self.items.count)")
400
374
 
401
375
  return self.items.count
402
376
 
@@ -430,7 +404,7 @@
430
404
 
431
405
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
432
406
 
433
- //tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.fade)
407
+
434
408
 
435
409
  print("Selected! (self.items[indexPath.row].title)")
436
410
 
@@ -469,3 +443,5 @@
469
443
  }
470
444
 
471
445
  }
446
+
447
+ ```