iOS 如何从 table 视图单元格 Swift 中的解析下载图像

iOS How to download image from parse in table view cell Swift

我在一个项目中工作,我需要在 table 视图单元格中显示图像,我在解析数据库中有这些图像。 我加载文本的代码:

   override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! cellRequestsTVC
    let good = data[indexPath.row]
    name = good["username"] as! String
    cell.userNameLable.text = "Name: \(name)"
    area = good["place"] as! String
    cell.areaLable.text = "Area: \(area)"
    cell.descriptionLable.text = good["description"] as? String
    cell.priorityLable.setRoundEdge()
cell.dataLable.text = good["openData"] as! String

    return cell
}

我有一个变量:

var data = [PFObject]()

如何在单元格中加载图像,使用解析?

在您的 cellForRowAt 方法中,像这样在后台获取 PFFile 数据。

let avatar = good["image"] as! PFFile
    avatar.getDataInBackground{ (imageData, error)in
        if imageData != nil {
            let image = UIImage(data: imageData!)
            cell.Image.image = image
        }
        else {
            print(error)
        }
    }