【发布时间】:2017-08-29 01:14:21
【问题描述】:
我正在尝试显示当前用户发布的所有图像。正如您在表格视图中的图片中看到的那样,每次当前用户发布图像时,它都会自动为当前用户信息下的图像创建一个唯一的 id。
在此图像中,您将看到,当用户发布图像时,它会为其子图像创建一个名为 media 的节点。
这是我的代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellMe", for: indexPath) as! MyPosttTableViewCell
FIRDatabase.database().reference().child("users").child(FIRAuth.auth()!.currentUser!.uid).observeSingleEvent(of: .value, with: { (snapshot) in
// check if user has photo
if snapshot.hasChild("media") != nil{
print("found it")
//set image locatin
let filePath = "\(FIRAuth.auth()!.currentUser!.uid)/\("media")"
FIRStorage.storage().reference().child(filePath).data(withMaxSize: 10*1024*1024, completion: { (data, error) in
let userPhoto = UIImage(data: data!)
cell.Myimages.image = userPhoto
})
}
else {
print("nil")
}
})
return cell
}}
【问题讨论】:
标签: ios swift firebase firebase-realtime-database firebase-storage