【发布时间】:2017-04-21 04:04:15
【问题描述】:
我目前正在尝试返回我的表格视图中具有 3 个属性等于“艺术”、“音乐”和“体育”的所有用户。具有不等于这 3 个字符串的 3 个属性的其他用户将不会显示在我的表格视图中。我如何实现这一目标?目前,我只能检查 ONE 属性是否等于 ONE 字符串,如下面的示例所示。下面是我的数据库树的图像,以及我目前拥有的代码。任何感谢任何帮助。谢谢!
class User: NSObject {
var name: String?
var email: String?
var numberId: String?
var attribute1: String?
var attribute2: String?
var attribute3: String?
var password: String?
var profileImageUrl: String?
}
func fetchUser() {
FIRDatabase.database().reference().child("users").queryOrdered(byChild: "attribute1").queryEqual(toValue: "art").observe(.childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let user = User()
user.setValuesForKeys(dictionary)
self.users.append(user)
DispatchQueue.main.async(execute: {
self.tableView.reloadData()
})
}
}, withCancel: nil)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! UserCell
let user = users[indexPath.row]
cell.textLabel?.text = user.name
cell .detailTextLabel?.text = user.email
if let profileImageUrl = user.profileImageUrl {
cell.profileImageView.loadImageUsingCachWithUrlString(urlString: profileImageUrl)
}
return cell
}
【问题讨论】:
标签: swift xcode firebase swift3 firebase-realtime-database