简体   繁体   English

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

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

I work with one project, and i need to show images in table view cell's, which i have in parse data base. 我处理一个项目,我需要在解析数据库中的表格视图单元格中显示图像。 My code to load text: 我的代码加载文本:

   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
}

And i have one variable: 我有一个变量:

var data = [PFObject]()

How i can load image in cell, used parse? 我如何在单元格中加载图像,使用解析?

In your cellForRowAt method get PFFile data in background like this. 在您的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)
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM