Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法将图像从Firebase提取到表视图_Ios_Swift_Xcode_Uiimage_Tableview - Fatal编程技术网

Ios 无法将图像从Firebase提取到表视图

Ios 无法将图像从Firebase提取到表视图,ios,swift,xcode,uiimage,tableview,Ios,Swift,Xcode,Uiimage,Tableview,有没有办法将downloadURL(链接)转换为UIImage到myTableViewController func loadPost() { Database.database().reference().child("Posts").observe(.childAdded, with: { (snapshot: DataSnapshot) in if let userDict = snapshot.value as? [St

有没有办法将
downloadURL
(链接)转换为
UIImage
到my
TableViewController

func loadPost() {                  
    Database.database().reference().child("Posts").observe(.childAdded, with: { (snapshot: DataSnapshot) in
            if let userDict = snapshot.value as? [String: Any] {
                let photoUrlString = userDict["photoUrl"] as! String
                let post = Posts(photoUrlString: photoUrlString)
                self.posts.append(post)
                print(self.posts)
                self.tableView.reloadData()
            }  
        })
    }

请尝试下载此图像。您可以在cellForRowAtIndexPath中使用此选项

func loadimage(_ url: URL)
{
    DispatchQueue.global().async { 
         if let data1 = try? Data(contentsOf: url){
           if let img = UIImage(data: data1){
             DispatchQueue.main.async {
                cell.imgView.image = img
             }
           }
        }
    }
}

很抱歉,我不明白。在这个方法中,你只需要传递图像url,它就会返回该url上的图像。一旦你在tableview手机上看到图像,你就有了。谢谢!对于示例代码!我是用“do,loop”语句完成的。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)

        cell.textLabel?.text = posts[indexPath.row].photoUrl

        let postImage = posts[indexPath.row]
        if let photoUrl = URL(string: postImage.photoUrl)
        {
            do {
                let data = try Data(contentsOf: photoUrl)
                cell.imageView?.image = UIImage (data: data)
            } catch {
                print("")
            }
        }

       return cell
    }