質問編集履歴
1
マークダウン形式に変更して、ソースを抜粋
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,8 +1,18 @@
|
|
1
|
+
### 前提・実現したいこと
|
2
|
+
|
1
3
|
下記のようなTableViewを作成しています
|
2
4
|
表示上はセルを追加されたように見えてもindexPathが増加していないため
|
3
5
|
didSelectRowAtのindexPathは常に一番目のデータが帰ってきます
|
4
6
|
どこがいけないんでしょうか?
|
5
7
|
|
8
|
+
### 発生している問題・エラーメッセージ
|
9
|
+
```
|
10
|
+
セルをタップしても、該当のIndexPathが取得できない
|
11
|
+
```
|
12
|
+
|
13
|
+
### 該当のソースコード
|
14
|
+
|
15
|
+
```Swift
|
6
16
|
import UIKit
|
7
17
|
import AVFoundation
|
8
18
|
import AudioToolbox
|
@@ -107,22 +117,10 @@
|
|
107
117
|
super.didReceiveMemoryWarning()
|
108
118
|
// Dispose of any resources that can be recreated.
|
109
119
|
}
|
110
|
-
|
111
|
-
let codeLabel:UILabel = {
|
112
|
-
let codeLabel = UILabel()
|
113
|
-
codeLabel.backgroundColor = .white
|
114
|
-
codeLabel.translatesAutoresizingMaskIntoConstraints = false
|
115
|
-
return codeLabel
|
116
|
-
}()
|
117
120
|
|
118
|
-
let codeFrame:UIView = {
|
119
|
-
let codeFrame = UIView()
|
120
|
-
|
121
|
+
override func viewWillAppear(_ animated: Bool) {
|
121
|
-
|
122
|
+
self.tableView.reloadData()
|
122
|
-
codeFrame.frame = CGRect.zero
|
123
|
-
codeFrame.translatesAutoresizingMaskIntoConstraints = false
|
124
|
-
return codeFrame
|
125
|
-
}
|
123
|
+
}
|
126
124
|
|
127
125
|
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
|
128
126
|
if metadataObjects.count == 0 {
|
@@ -144,11 +142,8 @@
|
|
144
142
|
self.items.append(self.item)
|
145
143
|
|
146
144
|
self.tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: UITableViewRowAnimation.right)
|
147
|
-
view.addSubview(codeFrame)
|
148
145
|
|
149
146
|
guard let barcodeObject = videoPreviewLayer?.transformedMetadataObject(for: metadataObject) else { return }
|
150
|
-
codeFrame.frame = barcodeObject.bounds
|
151
|
-
codeLabel.text = stringCodeValue
|
152
147
|
|
153
148
|
// Play system sound with custom mp3 file
|
154
149
|
if let customSoundUrl = Bundle.main.url(forResource: "beep-07", withExtension: "mp3") {
|
@@ -172,14 +167,6 @@
|
|
172
167
|
//displayDetailsViewController(scannedCode: stringCodeValue)
|
173
168
|
}
|
174
169
|
|
175
|
-
func displayDetailsViewController(scannedCode: String) {
|
176
|
-
|
177
|
-
let detailsViewController = DetailsViewController()
|
178
|
-
detailsViewController.scannedCode = scannedCode
|
179
|
-
//navigationController?.pushViewController(detailsViewController, animated: true)
|
180
|
-
present(detailsViewController, animated: true, completion: nil)
|
181
|
-
}
|
182
|
-
|
183
170
|
@objc func update(tm: Timer) {
|
184
171
|
counter += 1
|
185
172
|
//print(counter)
|
@@ -197,7 +184,7 @@
|
|
197
184
|
}
|
198
185
|
|
199
186
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
200
|
-
|
187
|
+
print("items.count (self.items.count)")
|
201
188
|
return self.items.count
|
202
189
|
}
|
203
190
|
|
@@ -214,7 +201,7 @@
|
|
214
201
|
}
|
215
202
|
|
216
203
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
217
|
-
|
204
|
+
|
218
205
|
print("Selected! (self.items[indexPath.row].title)")
|
219
206
|
print("indexPath (self.items[indexPath.row])")
|
220
207
|
|
@@ -233,4 +220,5 @@
|
|
233
220
|
tableView.deleteRows(at: [indexpath], with: UITableViewRowAnimation.fade)
|
234
221
|
}
|
235
222
|
}
|
236
|
-
}
|
223
|
+
}
|
224
|
+
```
|