回答編集履歴
1
UITableViewの基本的な書き方を追加
test
CHANGED
@@ -1 +1,61 @@
|
|
1
|
+
回答が大きく変わるのでメインの部分を書き換えちゃいます。
|
2
|
+
|
3
|
+
まず、UITableViewCellをoutlet接続する必要ないのかなと思いいました。カスタムセルを作っているわけでもないようなのでデフォルトならばこのようなコードでテーブルビューを表現することができます。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```Swift
|
8
|
+
|
9
|
+
|
10
|
+
|
1
|
-
UIViewController
|
11
|
+
class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSource {
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
@IBOutlet weak var tableView: UITableView!
|
16
|
+
|
17
|
+
//ここをCSVから読み込んだデータに書き換えてください.
|
18
|
+
|
19
|
+
let csvData = ["data1", "data2", "data3"]
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
override func viewDidLoad() {
|
24
|
+
|
25
|
+
tableView.delegate = self
|
26
|
+
|
27
|
+
tableView.dataSource = self
|
28
|
+
|
29
|
+
super.viewDidLoad()
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
34
|
+
|
35
|
+
return csvData.count
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
42
|
+
|
43
|
+
let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
|
44
|
+
|
45
|
+
cell.textLabel?.text = csvData[indexPath.row]
|
46
|
+
|
47
|
+
return cell
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
outlet接続しているのはStoryBoardに配置したUITableViewのみです。
|
60
|
+
|
61
|
+
![イメージ説明](6d8454007e45f3712143ea0737cdc3bd.png)
|