質問編集履歴
1
整形表示するようにいたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
```
|
2
|
+
|
1
3
|
import UIKit
|
2
4
|
|
3
5
|
|
@@ -14,125 +16,147 @@
|
|
14
16
|
|
15
17
|
|
16
18
|
|
17
|
-
class ViewController:UIViewController,UITableViewDelegate,UITableViewDataSource {
|
18
19
|
|
19
20
|
|
20
21
|
|
21
|
-
override func viewDidLoad() {
|
22
22
|
|
23
|
-
|
23
|
+
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
|
27
|
+
override func viewDidLoad() {
|
28
28
|
|
29
|
+
super.viewDidLoad()
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
let myTableView:UITableView!
|
34
|
+
|
29
|
-
myTableView = UITableView(frame : view.frame, style : .grouped)
|
35
|
+
myTableView = UITableView(frame : view.frame, style : .grouped)
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
myTableView.delegate = self
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
myTableView.dataSource = self
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
view.addSubview(myTableView)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
func numberOfSections(in tableView: UITableView) -> Int{
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
return sectionTitle.count
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
let sectionData = tableData[section]
|
76
|
+
|
77
|
+
return sectionData.count
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
return sectionTitle[section]
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
102
|
+
|
103
|
+
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
|
104
|
+
|
105
|
+
let sectionData = tableData[(indexPath as NSIndexPath).section]
|
106
|
+
|
107
|
+
let cellData = sectionData[(indexPath as NSIndexPath).row]
|
108
|
+
|
109
|
+
cell.textLabel?.text = cellData.0
|
110
|
+
|
111
|
+
cell.detailTextLabel?.text = cellData.1
|
112
|
+
|
113
|
+
return cell
|
114
|
+
|
115
|
+
}
|
30
116
|
|
31
117
|
|
32
118
|
|
33
|
-
|
119
|
+
|
34
120
|
|
121
|
+
|
35
122
|
|
123
|
+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
36
124
|
|
37
|
-
|
125
|
+
let title = sectionTitle[indexPath.section]
|
38
126
|
|
127
|
+
let sectionData = tableData[indexPath.section]
|
39
128
|
|
129
|
+
let cellData = sectionData[indexPath.row]
|
40
130
|
|
41
|
-
|
131
|
+
print("(title)(cellData.1)")
|
42
132
|
|
133
|
+
print("(cellData.0)")
|
43
134
|
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
override func didReceiveMemoryWarning() {
|
146
|
+
|
147
|
+
super.didReceiveMemoryWarning()
|
148
|
+
|
149
|
+
// Dispose of any resources that can be recreated.
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
44
154
|
|
45
155
|
}
|
46
156
|
|
47
157
|
|
48
158
|
|
49
|
-
|
50
|
-
|
51
|
-
func numberOfSections(in tableView: UITableView) -> Int{
|
52
|
-
|
53
|
-
return sectionTitle.count
|
54
|
-
|
55
|
-
|
159
|
+
```
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
|
62
|
-
|
63
|
-
let sectionData = tableData[section]
|
64
|
-
|
65
|
-
return sectionData.count
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
74
|
-
|
75
|
-
return sectionTitle[section]
|
76
|
-
|
77
|
-
}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
84
|
-
|
85
|
-
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
|
86
|
-
|
87
|
-
let sectionData = tableData[(indexPath as NSIndexPath).section]
|
88
|
-
|
89
|
-
let cellData = sectionData[(indexPath as NSIndexPath).row]
|
90
|
-
|
91
|
-
cell.textLabel?.text = cellData.0
|
92
|
-
|
93
|
-
cell.detailTextLabel?.text = cellData.1
|
94
|
-
|
95
|
-
return cell
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
106
|
-
|
107
|
-
let title = sectionTitle[indexPath.section]
|
108
|
-
|
109
|
-
let sectionData = tableData[indexPath.section]
|
110
|
-
|
111
|
-
let cellData = sectionData[indexPath.row]
|
112
|
-
|
113
|
-
print("(title)(cellData.1)")
|
114
|
-
|
115
|
-
print("(cellData.0)")
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
override func didReceiveMemoryWarning() {
|
128
|
-
|
129
|
-
super.didReceiveMemoryWarning()
|
130
|
-
|
131
|
-
// Dispose of any resources that can be recreated.
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
}
|
136
160
|
|
137
161
|
|
138
162
|
|
@@ -150,6 +174,8 @@
|
|
150
174
|
|
151
175
|
}
|
152
176
|
|
177
|
+
|
178
|
+
|
153
179
|
各セクションの値が入った配列「tableData」を「sectionData」に取り出して、sectionDataの個数を返していると思いますが、let sectionData = tableData[section]という文でなぜtableDataの後ろに[seciton]をつけているのかがわかりません)
|
154
180
|
|
155
181
|
|