【问题标题】:Can't convert PFFile to UIImage using getDataInBackgroundWithBlock无法使用 getDataInBackgroundWithBlock 将 PFFile 转换为 UIImage
【发布时间】:2016-11-01 18:15:28
【问题描述】:

我有一个 updateCell 函数,我在 tableView 函数中调用它。

我正在尝试更新单元格并将 PFFile 转换为 UIImage,但我不断收到错误 Cannot convert value of type '(NSData?, NSError?) -> Void' to expected argument type 'PFDataResultBlock?'

当我从 Parse 文档中得到这个时,我感到很困惑,我无法终生找到解决方案或哪里出错了。这是我的 updateUI 函数。

func updateUI(venue: Venue) {
        venueLabel.text = venue.name
        let venueImageFile = venue.image

        venueImageFile.getDataInBackgroundWithBlock {
            (imageData: NSData?, error: NSError?) -> Void in
            if error == nil {
                if let imageData = imageData {
                    let image = UIImage(data:imageData)
                }
            }
        }
    }

这里是 Venue 类

class Venue {

    private var _name: String!
    private var _location: String!
    private var _image: PFFile!

    var name: String {
        return _name
    }

    var location: String {
        return _location
    }

    var image: PFFile {
        return _image
    }

    init(name: String, location: String, image: PFFile) {
        self._name = name
        self._location = location
        self._image = image
    }
}

非常感谢任何帮助。到了现在不知道该往哪里转的地步。

【问题讨论】:

    标签: swift parse-platform uiimage


    【解决方案1】:

    基本上我找不到使用 getDataInBackgroundWithBlock 的解决方案,所以我最终安装了 Parse UI,它完美地解释了它......

    PFImageView

    许多应用程序需要将存储在 Parse Cloud 中的图像显示为 PFFiles。 但是,使用内置 UIImageView 加载远程图像涉及 编写多行样板代码。 PFImageView 简化了这一点 通过抽象出这些部分来完成任务。

    一旦我将它导入到我的 swift 文件中,我所要做的就是:

    @IBOutlet weak var venueImage: PFImageView! // Make sure it's this class in the storyboard. It's default would be UIImageView.
    
    func updateUI(venue: Venue) {
        venueLabel.text = venue.name
    
        venueImage.file = venue.image
        venueImage.loadInBackground()
    }
    

    :)

    【讨论】:

      猜你喜欢
      • 2015-09-04
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 2017-05-07
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 2015-08-22
      相关资源
      最近更新 更多