从Parse下载PFFile(图像)将其追加到数组中,并用该数组填充UIImageView(快速) [英] Downloading PFFile (Image) from Parse append it to array and fill UIImageView with that array (Swift)
问题描述
我在解析和快速处理方面遇到问题,希望您能为我提供帮助:)
I have a problem with parse and swift and i hope you can help me :)
我正在从Parse下载字符串和PFfile,并希望将其添加到数组中(效果很好).
I'm downloading strings and PFfiles from Parse and want to add it to an array (this works fine).
然后我想用字符串数组(也可以正常工作)填充Label,并用PFFile数组(也是图像)填充UIImageView.
Then I want to fill a Label with the string array (works fine as well) and an UIImageView with the PFFile array which is also an Image.
但是我总是会出错:
PFFile不能转换为"UIImage
PFFile is not convertible to "UIImage
但是我不知道如何转换此PFFile,以便可以与UIImage View一起使用.
But I have no clue how I can convert this PFFile so that I can use it with the UIImage View.
var titles = [String] ()
var fragenImages = [PFFile] ()
@IBOutlet weak var fragenIm: UIImageView!
@IBOutlet weak var fragenFeld: UILabel!
override func viewDidAppear(animated: Bool) {
var query = PFQuery(className:"Post")
query.whereKey("user", notEqualTo: PFUser.currentUser().username)
query.limit = 5
query.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
for object in objects {
self.titles.append(object["title"] as String)
self.fragenImages.append(object["imageFile"] as PFFile)
}
self.fragenFeld.text = self.titles[0]
self.fragenIm.image = self.fragenImages[0]
}
else {
println(error)
}
}
}
推荐答案
丹尼尔(Daniel),图片不是文件,从技术上讲,它们是文件,但您将它们引用为数据而不是PFObjects或PFFiles.因此,从本质上来说,获取文件的数据并按照通常的方式进行应用即可:您只是错过了一个简单的步骤:
Daniel, pictures aren't files, technically they are, but you reference them as Data not PFObjects or PFFiles. So, essentially get the Data of the file and apply as you normally would: You just missed a simple step:
for object in objects {
let userPicture = object["imageFile"] as PFFile
userPicture.getDataInBackgroundWithBlock({ // This is the part your overlooking
(imageData: NSData!, error: NSError!) -> Void in
if (error == nil) {
let image = UIImage(data:imageData)
self.fragenImages.append(image)
}
})
}
这篇关于从Parse下载PFFile(图像)将其追加到数组中,并用该数组填充UIImageView(快速)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!