質問編集履歴
5
コード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,3 +27,115 @@
|
|
27
27
|
Xcode 12.2
|
28
28
|
|
29
29
|
Swift 5.3.1
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
### こんな感じでやりたくてコードは作ってみたもののうまくゆかない
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```Swift
|
38
|
+
|
39
|
+
import UIKit
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
class TableViewController: UITableViewController {
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
typealias MySectionRow = (mySection: String, myRow: Array<String>)
|
48
|
+
|
49
|
+
var mySectionRows = [MySectionRow]()
|
50
|
+
|
51
|
+
var selectedClass = ""
|
52
|
+
|
53
|
+
var selectedPerson = ""
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
var birthPlace = ["東京","千葉","埼玉","神奈川","茨城","山梨"]
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
override func viewDidLoad() {
|
62
|
+
|
63
|
+
super.viewDidLoad()
|
64
|
+
|
65
|
+
mySectionRows.append(("3年A組",["井上","加藤","田中"]))
|
66
|
+
|
67
|
+
mySectionRows.append(("3年B組",["鈴木","吉田"]))
|
68
|
+
|
69
|
+
mySectionRows.append(("3年C組",["遠藤","佐藤","村田","山田"]))
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
override func numberOfSections(in tableView: UITableView) -> Int {
|
76
|
+
|
77
|
+
return mySectionRows.count
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
84
|
+
|
85
|
+
return mySectionRows[section].myRow.count
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
92
|
+
|
93
|
+
return mySectionRows[section].mySection
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
100
|
+
|
101
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "Reuse", for: indexPath)
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
let label1Text = cell.viewWithTag(1) as! UILabel
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
label1Text.text = mySectionRows[indexPath.section].myRow[indexPath.row]
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
let label2Text = cell.viewWithTag(2) as! UILabel
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
label2Text.text = birthPlace[indexPath.row]
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
return cell
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
128
|
+
|
129
|
+
selectedClass = mySectionRows[indexPath.section].mySection
|
130
|
+
|
131
|
+
selectedPerson = mySectionRows[indexPath.section].myRow[indexPath.row]
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
```
|
4
タイトル一部修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
セルで苗字に紐づいて表示させたい
|
1
|
+
Swift セルで苗字に紐づいて表示させたい
|
test
CHANGED
File without changes
|
3
一部修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
https://qiita.com/BMJr/items/ca7bcf76d36acbdef75e
|
5
|
+
[https://qiita.com/BMJr/items/ca7bcf76d36acbdef75e](https://qiita.com/BMJr/items/ca7bcf76d36acbdef75e)
|
6
6
|
|
7
7
|
上記のサイトの2つ目の方法で表示させるところまではできました。
|
8
8
|
|
2
タイトル追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
苗字に紐づいて表示させたい
|
1
|
+
セルで苗字に紐づいて表示させたい
|
test
CHANGED
File without changes
|
1
タイトル修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
苗字に紐づいて表示させたい
|
test
CHANGED
File without changes
|