我如何在名为users的路径名为pc的节点中对firebase存储中的图像进行表示。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : viewTableViewCell = tableView.dequeueReusableCell(withIdentifier: "opa", for:indexPath) as! viewTableViewCell
if let post = posts[indexPath.row] {
cell.post.text = post
cell.name.text = self.loggedinuserdata!["name"] as! String
cell.handle.text = self.loggedinuserdata!["handle"] as! String
cell.pc.image = self.loggedinuserdata!["pc"] as! UIImage
}
return cell
}
感谢您的期待))
答案 0 :(得分:0)
试试这个:
cell.pc.image = UIImage.init(named: self.loggedinuserdata!["pc"] as! String)
如果从网址获取图片
cell.pc.sd_setImage(with: URL(string: self.loggedinuserdata!["pc"] as! String), placeholderImage: nil)
答案 1 :(得分:0)
首先您需要编写此函数并将url作为参数传递
func downloadImageFromUrl(imageUrl: String, completion: @escaping (_ success: UIImage) -> Void) {
let url = URL(string: imageUrl)
let task = URLSession.shared.dataTask(with: url!) { data, response, error in
guard let data = data, error == nil else { return }
completion(UIImage(data: data)!)
}
task.resume()
}
并将其称为
self.downloadImageFromUrl(imageUrl: self.loggedinuserdata!["pc"] as! String , completion: { image in
cell.pc.image = image
})