質問編集履歴
1
コードと写真の追加
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -30,4 +30,110 @@
|
|
|
30
30
|
```
|
|
31
31
|
という形で行っている。
|
|
32
32
|
|
|
33
|
-
よろしくお願いします。
|
|
33
|
+
よろしくお願いします。
|
|
34
|
+
|
|
35
|
+
追記
|
|
36
|
+
みなさまコメント・回答ありがとうございます。
|
|
37
|
+
```
|
|
38
|
+
import UIKit
|
|
39
|
+
import Firebase
|
|
40
|
+
import FirebaseAuth
|
|
41
|
+
class JoinedRoomViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@IBOutlet weak var roomTableView: UITableView!
|
|
46
|
+
@IBOutlet weak var protocolButton: UIBarButtonItem!
|
|
47
|
+
var reportBool = false
|
|
48
|
+
var userDefaults = UserDefaults.standard
|
|
49
|
+
var joinedRoomName: [String?] = []
|
|
50
|
+
var joinedRoomPassword: [String?] = []
|
|
51
|
+
var password = ""
|
|
52
|
+
let cellSpacingHeight: CGFloat = 5
|
|
53
|
+
override func viewDidLoad() {
|
|
54
|
+
super.viewDidLoad()//追加
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
overrideUserInterfaceStyle = .light
|
|
59
|
+
self.navigationController?.navigationBar.barTintColor = UIColor(red: 24/255, green: 129/255, blue: 124/255, alpha: 1.0)
|
|
60
|
+
self.navigationController?.navigationBar.tintColor = .white
|
|
61
|
+
self.navigationController?.navigationBar.titleTextAttributes = [
|
|
62
|
+
.foregroundColor: UIColor.white
|
|
63
|
+
]
|
|
64
|
+
roomTableView.delegate = self
|
|
65
|
+
roomTableView.dataSource = self
|
|
66
|
+
}
|
|
67
|
+
override func viewWillAppear(_ animated: Bool) {
|
|
68
|
+
super.viewWillAppear(animated)
|
|
69
|
+
joinedRoomName = (userDefaults.array(forKey: "name") ?? []) as [String]
|
|
70
|
+
|
|
71
|
+
joinedRoomPassword = (userDefaults.array(forKey: "password") ?? []) as [String]
|
|
72
|
+
if Auth.auth().currentUser == nil {
|
|
73
|
+
print("ログインしていない")
|
|
74
|
+
|
|
75
|
+
performSegue(withIdentifier: "ban", sender: nil)
|
|
76
|
+
|
|
77
|
+
} else {
|
|
78
|
+
print("ログインしていてidは(Auth.auth().currentUser?.uid)")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
roomTableView.reloadData()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func numberOfSections(in tableView: UITableView) -> Int {
|
|
87
|
+
return self.joinedRoomName.count
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
92
|
+
|
|
93
|
+
let cell:UITableViewCell = (self.roomTableView.dequeueReusableCell(withIdentifier: "cell") as UITableViewCell?)!
|
|
94
|
+
|
|
95
|
+
// note that indexPath.section is used rather than indexPath.row
|
|
96
|
+
cell.textLabel?.text = self.joinedRoomName[indexPath.section]
|
|
97
|
+
|
|
98
|
+
cell.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
|
|
99
|
+
cell.layer.shadowColor = UIColor.black.cgColor
|
|
100
|
+
cell.layer.shadowOpacity = 0.6
|
|
101
|
+
cell.layer.shadowRadius = 4
|
|
102
|
+
cell.clipsToBounds = true
|
|
103
|
+
return cell
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
performSegue(withIdentifier: "cellSegue", sender: nil)
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
private func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
|
|
113
|
+
return 44
|
|
114
|
+
}
|
|
115
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
116
|
+
return 1
|
|
117
|
+
}
|
|
118
|
+
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
119
|
+
return cellSpacingHeight
|
|
120
|
+
}
|
|
121
|
+
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
122
|
+
let headerView = UIView()
|
|
123
|
+
headerView.backgroundColor = UIColor.clear
|
|
124
|
+
return headerView
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
128
|
+
|
|
129
|
+
let indexPath = self.roomTableView.indexPathForSelectedRow
|
|
130
|
+
let NextVC = segue.destination as! ChatViewController
|
|
131
|
+
NextVC.roomName = self.joinedRoomName[indexPath!.section]!
|
|
132
|
+
NextVC.roomPassword = self.joinedRoomPassword[indexPath!.section]!
|
|
133
|
+
NextVC.password = "(joinedRoomName[indexPath!.section]!)(joinedRoomPassword[indexPath!.section]!)"
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+

|
|
138
|
+
|
|
139
|
+
コードと遷移の写真を追加しました。
|