gpt4 book ai didi

swift - 无法使用 getDataInBackgroundWithBlock 将 PFFile 转换为 UIImage

转载 作者:行者123 更新时间:2023-11-30 12:56:16 25 4
gpt4 key购买 nike

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

我正在尝试更新单元格并将 PFFile 转换为 UIImage,但我不断收到错误无法将类型“(NSData?, NSError?) -> Void”的值转换为预期参数类型“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
}
}

非常感谢任何帮助。现在我不知道该转向哪里。

最佳答案

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

PFImageView

Many apps need to display images stored in the Parse Cloud as PFFiles. However, to load remote images with the built-in UIImageView involves writing many lines of boilerplate code. PFImageView simplifies this task by abstracting away these parts.

一旦我将其导入到我的 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()
}

:)

关于swift - 无法使用 getDataInBackgroundWithBlock 将 PFFile 转换为 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40366109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com