现在它从数据库中提取所有信息。我希望它只从数据库中具有 storename
的用户中提取信息。
我可以检索所有内容,但哪一个没有 storename
它将在我的应用程序中显示空表。
我的代码如何检索它
override func viewDidLoad() {
super.viewDidLoad()
let refList = Database.database().reference().child("Users/Sellers")
refList.observe(DataEventType.value, with:{(snapshot) in
if snapshot.childrenCount>0{
self.listProduct.removeAll()
for lists in snapshot.children.allObjects as! [DataSnapshot]{
let productList = lists.childSnapshot(forPath: "user_info")
let userList = productList.value as? [String: AnyObject]
let listName = userList?["storename"]
// print("the Key value \(lists.key) " )
print("key = \(self.shops)")
let list = StoreModel(name: listName as! String?)
self.shops.append(Shop(storename: listName as! String?, shop_id: lists.key ))
self.listProduct.append(list)
}
self.tableList.reloadData()
}
})
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return listProduct.count
}
我希望它只从数据库中具有 storename
的用户中提取信息并显示在我的表格 View 中。
最佳答案
你可以试试
refList.observe(.value, with:{(snapshot) in
if snapshot.childrenCount > 0 {
self.listProduct.removeAll()
for lists in snapshot.children.allObjects as! [DataSnapshot]{
let productList = lists.childSnapshot(forPath: "user_info")
let userList = productList.value as? [String: AnyObject]
if let listName = userList?["storename"] as? String {
let list = StoreModel(name: listName)
self.shops.append(Shop(storename: listName, shop_id: lists.key ))
self.listProduct.append(list)
}
}
self.tableList.reloadData()
}
})
关于swift - 如何从 firebase 仅检索 UID 并在 TableView 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56239059/