无法转换类型' __ NSCFString' (0x10d33c4a0)到​​' UIImage

时间:2017-06-20 08:48:32

标签: ios firebase swift3 uiimage firebase-storage

我如何在名为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

}

感谢您的期待))

2 个答案:

答案 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)

SDWebImage Source

答案 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

  })