【发布时间】:2017-11-07 03:04:32
【问题描述】:
我对编码非常陌生,并且正在尝试学习如何从 Firebase 获取我的用户信息!
我最近添加了从 firebase 获取经度和纬度坐标的代码。不幸的是,当我运行应用程序时,我再也看不到视图控制器中的用户了。在添加代码之前,用户会完美地显示出来。`
func retrieveUsers(){
//this is where you will also have to call the users location
let ref = Database.database().reference()
ref.child("users").queryOrderedByKey().observeSingleEvent(of: .value, with: { snapshot in
let users = snapshot.value as! [String: AnyObject]
self.user.removeAll()
for (_,value) in users {
if let uid = value["uid"] as? String {
if uid != Auth.auth().currentUser!.uid {
let userToShow = User()
if let fullName = value["full name"] as? String, let imagePath = value["urlToImage"] as? String
,let userLongitude = value["long"] as? String, let userLatitude = value["lat"] as? String
//for some reason adding this makes it impossible to get code
//userLongitude and userLatitude cause no users to show up
{
userToShow.fullName = fullName
userToShow.imagePath = imagePath
userToShow.userID = uid
userToShow.userLongitude = userLongitude
userToShow.userLatitude = userLatitude
self.user.append(userToShow)
}
}
}
}
self.tableview.reloadData()
})
ref.removeAllObservers()
}
`
这里有更多与这个问题相关的代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableview.dequeueReusableCell(withIdentifier: "userCell", for: indexPath) as! UserCell
cell.nameLabel.text = self.user[indexPath.row].fullName
cell.userID = self.user[indexPath.row].userID
cell.userImage.downloadImage(from: self.user[indexPath.row].imagePath!)
cell.longLabel.text = self.user[indexPath.row].userLongitude
cell.latLabel.text = self.user[indexPath.row].userLatitude
//I believe that you need to go to userCell and define these variables
return cell
}
【问题讨论】:
-
请在
self.tableview.reloadData()之前添加此语句print(self.user)并检查它打印的内容? -
它没有打印任何东西。
-
你能展示一下你的firebase数据库的结构吗?
标签: ios swift firebase firebase-realtime-database core-location