質問編集履歴
2
mod
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
iOSのTableViewでsectionの表示方法
|
test
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
Swift 4.0
|
2
|
+
|
3
|
+
Xcode 9.1
|
4
|
+
|
5
|
+
|
6
|
+
|
1
7
|
以下のような記事を参考にTableViewのセクションわけを作成しましたが、画像のように一つ目のセクション?しか表示されません。どこに問題があるのでしょうか?
|
2
8
|
|
3
9
|
そもそも、引数の `section` なるものはどこから取ってきているのか疑問です。
|
1
mod
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
iOSのTableViewでsectionの表示方法
|
1
|
+
diOSのTableViewでsectionの表示方法
|
test
CHANGED
@@ -10,4 +10,92 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
+
```
|
14
|
+
|
15
|
+
import UIKit
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
class SettingsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
|
20
|
+
|
21
|
+
let firstOptions: Array = ["設定"]
|
22
|
+
|
23
|
+
let secondOptions: Array = ["設定"]
|
24
|
+
|
25
|
+
let sections: Array = ["hoge", "foo"]
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
30
|
+
|
31
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "ConfigCell", for: indexPath)
|
32
|
+
|
33
|
+
if indexPath.section == 0 {
|
34
|
+
|
35
|
+
cell.textLabel?.text = "hogehoge"
|
36
|
+
|
37
|
+
} else if indexPath.section == 1 {
|
38
|
+
|
39
|
+
cell.textLabel?.text = "hogehoge"
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
return cell
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
|
50
|
+
|
51
|
+
return self.sections.count
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
58
|
+
|
59
|
+
return sections[section]
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
66
|
+
|
67
|
+
if section == 0 {
|
68
|
+
|
69
|
+
return firstOptions.count
|
70
|
+
|
71
|
+
} else if section == 1 {
|
72
|
+
|
73
|
+
return secondOptions.count
|
74
|
+
|
75
|
+
} else {
|
76
|
+
|
77
|
+
return 0
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
override func viewDidLoad() {
|
86
|
+
|
87
|
+
self.navigationItem.title = "設定"
|
88
|
+
|
89
|
+
super.viewDidLoad()
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
|
100
|
+
|
13
101
|
![画面](2c7368d445766ecda6f3fb3ad7223f38.jpeg)
|