質問編集履歴

2

ソースコードの追加

2020/12/05 16:33

投稿

Ogikubo
Ogikubo

スコア1

test CHANGED
File without changes
test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
 
42
42
 
43
- ```swift
43
+ ```tableviewController
44
44
 
45
45
  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
46
46
 
@@ -96,9 +96,81 @@
96
96
 
97
97
  }
98
98
 
99
+ ```
100
+
101
+ ```TimeLineModel
102
+
103
+ import Foundation
104
+
105
+ import Firebase
99
106
 
100
107
 
108
+
109
+ class TimeLineModel {
110
+
111
+
112
+
113
+ var musicName:String = ""
114
+
115
+ var groupName:String = ""
116
+
117
+ var constitution:String = ""
118
+
119
+ var ref = Firestore.firestore().collection("timeLine")
120
+
121
+
122
+
123
+
124
+
125
+ init(musicName:String,groupName:String,constitution:String) {
126
+
127
+
128
+
129
+ self.musicName = musicName
130
+
131
+ self.groupName = groupName
132
+
133
+ self.constitution = constitution
134
+
101
- ```
135
+ }
136
+
137
+
138
+
139
+ init(document:QueryDocumentSnapshot) {
140
+
141
+
142
+
143
+ if let value = document.data() as? [String:Any] {
144
+
145
+
146
+
147
+ musicName = value["musicName"] as! String
148
+
149
+ groupName = value["groupName"] as! String
150
+
151
+ constitution = value["constitution"] as! String
152
+
153
+ }
154
+
155
+ }
156
+
157
+
158
+
159
+ func toContents() -> [String:Any] {
160
+
161
+ return ["musicName":musicName,"groupName":groupName,"constitution":constitution]
162
+
163
+ }
164
+
165
+
166
+
167
+ func save() {
168
+
169
+ ref.addDocument(data: toContents())
170
+
171
+ }
172
+
173
+
102
174
 
103
175
  ```
104
176
 

1

誤字

2020/12/05 16:33

投稿

Ogikubo
Ogikubo

スコア1

test CHANGED
File without changes
test CHANGED
@@ -42,13 +42,63 @@
42
42
 
43
43
  ```swift
44
44
 
45
- ![イメージ説明](28d033d5917d78d8a55717e5a2bddff9.png)
45
+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
46
46
 
47
- ![イメージ説明](97fb7738620eb993077ee95a23ee2abe.png)
47
+ let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TimeLineCell
48
48
 
49
- ![![イメージ説明](963e8aa3c1b545359d1b8aef6da3d149.png)
49
+ cell.timeLineModel = self.timeLines[indexPath.row]
50
50
 
51
+
52
+
53
+ return cell
54
+
55
+ }
56
+
57
+
58
+
59
+ override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
60
+
61
+
62
+
63
+ let selectedCell = tableView.cellForRow(at: indexPath)
64
+
65
+ musicName = timeLines[indexPath.row].musicName
66
+
67
+ groupName = timeLines[indexPath.row].groupName
68
+
69
+ constitution = timeLines[indexPath.row].constitution
70
+
71
+
72
+
73
+ performSegue(withIdentifier: "detail", sender: nil)
74
+
75
+ }
76
+
77
+
78
+
79
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
80
+
81
+
82
+
51
- ![イメージ説明](dd9aa627803a837421d332868a44ae01.png)
83
+ if segue.identifier == "detail" {
84
+
85
+
86
+
87
+ let detailViewController = segue.destination as! DetailViewController
88
+
89
+
90
+
91
+ detailViewController.musicName = musicName
92
+
93
+ detailViewController.groupName = groupName
94
+
95
+ detailViewController.constitution = constitution
96
+
97
+ }
98
+
99
+
100
+
101
+ ```
52
102
 
53
103
  ```
54
104