質問編集履歴

1

コードと写真の追加

2020/07/01 22:52

投稿

Hyperbolic4183
Hyperbolic4183

スコア17

test CHANGED
File without changes
test CHANGED
@@ -63,3 +63,215 @@
63
63
 
64
64
 
65
65
  よろしくお願いします。
66
+
67
+
68
+
69
+ 追記
70
+
71
+ みなさまコメント・回答ありがとうございます。
72
+
73
+ ```
74
+
75
+ import UIKit
76
+
77
+ import Firebase
78
+
79
+ import FirebaseAuth
80
+
81
+ class JoinedRoomViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ @IBOutlet weak var roomTableView: UITableView!
90
+
91
+ @IBOutlet weak var protocolButton: UIBarButtonItem!
92
+
93
+ var reportBool = false
94
+
95
+ var userDefaults = UserDefaults.standard
96
+
97
+ var joinedRoomName: [String?] = []
98
+
99
+ var joinedRoomPassword: [String?] = []
100
+
101
+ var password = ""
102
+
103
+ let cellSpacingHeight: CGFloat = 5
104
+
105
+ override func viewDidLoad() {
106
+
107
+ super.viewDidLoad()//追加
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+ overrideUserInterfaceStyle = .light
116
+
117
+ self.navigationController?.navigationBar.barTintColor = UIColor(red: 24/255, green: 129/255, blue: 124/255, alpha: 1.0)
118
+
119
+ self.navigationController?.navigationBar.tintColor = .white
120
+
121
+ self.navigationController?.navigationBar.titleTextAttributes = [
122
+
123
+ .foregroundColor: UIColor.white
124
+
125
+ ]
126
+
127
+ roomTableView.delegate = self
128
+
129
+ roomTableView.dataSource = self
130
+
131
+ }
132
+
133
+ override func viewWillAppear(_ animated: Bool) {
134
+
135
+ super.viewWillAppear(animated)
136
+
137
+ joinedRoomName = (userDefaults.array(forKey: "name") ?? []) as [String]
138
+
139
+
140
+
141
+ joinedRoomPassword = (userDefaults.array(forKey: "password") ?? []) as [String]
142
+
143
+ if Auth.auth().currentUser == nil {
144
+
145
+ print("ログインしていない")
146
+
147
+
148
+
149
+ performSegue(withIdentifier: "ban", sender: nil)
150
+
151
+
152
+
153
+ } else {
154
+
155
+ print("ログインしていてidは(Auth.auth().currentUser?.uid)")
156
+
157
+
158
+
159
+
160
+
161
+ }
162
+
163
+
164
+
165
+ roomTableView.reloadData()
166
+
167
+ }
168
+
169
+
170
+
171
+ func numberOfSections(in tableView: UITableView) -> Int {
172
+
173
+ return self.joinedRoomName.count
174
+
175
+ }
176
+
177
+
178
+
179
+
180
+
181
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
182
+
183
+
184
+
185
+ let cell:UITableViewCell = (self.roomTableView.dequeueReusableCell(withIdentifier: "cell") as UITableViewCell?)!
186
+
187
+
188
+
189
+ // note that indexPath.section is used rather than indexPath.row
190
+
191
+ cell.textLabel?.text = self.joinedRoomName[indexPath.section]
192
+
193
+
194
+
195
+ cell.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
196
+
197
+ cell.layer.shadowColor = UIColor.black.cgColor
198
+
199
+ cell.layer.shadowOpacity = 0.6
200
+
201
+ cell.layer.shadowRadius = 4
202
+
203
+ cell.clipsToBounds = true
204
+
205
+ return cell
206
+
207
+ }
208
+
209
+
210
+
211
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
212
+
213
+
214
+
215
+
216
+
217
+ performSegue(withIdentifier: "cellSegue", sender: nil)
218
+
219
+
220
+
221
+ }
222
+
223
+ private func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
224
+
225
+ return 44
226
+
227
+ }
228
+
229
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
230
+
231
+ return 1
232
+
233
+ }
234
+
235
+ func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
236
+
237
+ return cellSpacingHeight
238
+
239
+ }
240
+
241
+ func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
242
+
243
+ let headerView = UIView()
244
+
245
+ headerView.backgroundColor = UIColor.clear
246
+
247
+ return headerView
248
+
249
+ }
250
+
251
+
252
+
253
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
254
+
255
+
256
+
257
+ let indexPath = self.roomTableView.indexPathForSelectedRow
258
+
259
+ let NextVC = segue.destination as! ChatViewController
260
+
261
+ NextVC.roomName = self.joinedRoomName[indexPath!.section]!
262
+
263
+ NextVC.roomPassword = self.joinedRoomPassword[indexPath!.section]!
264
+
265
+ NextVC.password = "(joinedRoomName[indexPath!.section]!)(joinedRoomPassword[indexPath!.section]!)"
266
+
267
+
268
+
269
+ }
270
+
271
+ ```
272
+
273
+ ![遷移の詳細](93b47ca7aab6635c14fa38b33d81638d.jpeg)
274
+
275
+
276
+
277
+ コードと遷移の写真を追加しました。