ios - 将两个从两个独立的firebase数据库加载到一个tableview swift中
<p><p>我正在构建一个非常简单的应用程序,人们在其中单击一个按钮,并使用 firebase 数据库记录他们单击按钮( checkin )的时间。我没有问题<strong>存储</strong>签到人员的数据,然后显示签到人员的数据以及所有适当的信息。我已经包含了一张图片来显示我已经在我的 TableViewController 中显示的内容。
<a href="/image/nyr7I.png" rel="noreferrer noopener nofollow"><img src="/image/nyr7I.png" alt="This is what my TableView shows right now"/></a> </p>
<p>我不想只显示已 checkin 的用户我还想显示尚未 checkin 的用户。</p>
<p>我现在将分享一张照片,说明我的 firebase 数据库是如何设置为存储每个用户的。 </p>
<p> <a href="/image/Mrf9T.png" rel="noreferrer noopener nofollow"><img src="/image/Mrf9T.png" alt="How my database is setup to store all users"/></a> </p>
<p>这是整个数据库的 View ,其中显示了用户和已经 checkin 的用户以及名称和时间戳</p>
<p> <a href="/image/iViCw.png" rel="noreferrer noopener nofollow"><img src="/image/iViCw.png" alt="Entire database"/></a> </p>
<p>我还将包含我的 UITableViewController 中的代码,这样每个人都可以看到我如何只显示已经签到的人。</p>
<pre><code> import Firebase
struct checkInStruct {
let userName : String!
let hour : String!
let minutes : String!
}
class checkInDaysTableViewController: UITableViewController {
//Variables
var lastChildNameSegue = ""
var posts = ()
let user = FIRAuth.auth()?.currentUser
override func viewDidLoad() {
super.viewDidLoad()
let databaseRef = FIRDatabase.database().reference()
let userID = user?.uid
databaseRef.child("users").child("\(userID!)").child("checkins").child("\(lastChildNameSegue)").queryOrderedByKey().observe(.childAdded, with: { (snapshot) in
let userNameSnapValue = snapshot.value as? NSDictionary
let userName = userNameSnapValue?["userName"] as? String
let hourSnapValue = snapshot.value as? NSDictionary
let hour = hourSnapValue?["hour"] as? String
let minutesValue = snapshot.value as? NSDictionary
let minutes = minutesValue?["minutes"] as? String
print(userName!)
print(hour!)
print(minutes!)
self.posts.insert(checkInStruct(userName: userName, hour: hour, minutes: minutes) , at: 0)
self.tableView.reloadData()
})
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
let userName = posts.userName
let hour = posts.hour
var minute = posts.minutes
let minuteInt = Int(minute!)
if(minuteInt! >= 0 && minuteInt! <= 9){
let minuteWithZero = "0\(minuteInt!)"
minute = minuteWithZero
}
let label1 = cell?.viewWithTag(1) as! UILabel
label1.text = "\(userName!)"
let label2 = cell?.viewWithTag(2) as! UILabel
label2.text = "Checked In At \(hour!):\(minute!)"
return cell!
}
}
</code></pre>
<p><strong>我需要做什么才能加载所有用户的数据并以红色突出显示尚未签到的任何人?</strong></p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为你应该这样设计你的数据库。</p>
<p><code>root -> 用户</code></p>
<pre><code>"users": [
"{id_user_A}": {
"name": A,
"checkedin": [
"{id_checkedin_1}": {
...
},
"{id_checkedin_2}": {
...
}
]
},
"{id_user_B}": {
"name": B,
"checkedin": []
}
]
</code></pre>
<p>并获取所有用户,使用 <code>checkedin</code> 属性检查每个用户以了解哪个用户 checkin 。</p></p>
<p style="font-size: 20px;">关于ios - 将两个从两个独立的firebase数据库加载到一个tableview swift中,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42730405/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42730405/
</a>
</p>
页:
[1]