本文介绍了如何从 Parse 检索图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 Heroku 上托管的解析服务器获取图像.到目前为止,我已经获得了 Text 值,但图像是唯一的问题.
I'm trying to get an image from a parse server that is hosted on Heroku. So far I have gotten the Text values but the images are the only problem.
这是我目前的代码:
// Getting Info from servers
let dataQ = PFQuery(className: "message")
dataQ.findObjectsInBackground { (objects: [PFObject]?, error: Error?) -> Void in
if error == nil {
for object in objects! {
self.sentFromLabel.text = object["sender"] as? String
// Get Image from server
object["Picture"].getDataInBackgroundWithBlock
}
} else {
print(error)
}
}
到目前为止,当我使用 .getDataInBackgroundWithBlock
时,它给了我一个错误.我不知道为什么.允许我从服务器获取图像的 Swift 3 版本是什么?
So far when I use .getDataInBackgroundWithBlock
it gives me an error. I have no clue why. What is the Swift 3 version to allow me to get an image from the server?
推荐答案
这是一个 swift 3 示例!
Here is a swift 3 example!
@IBOutlet weak var fullImage : UIImageView!
//place this in your for loop
let imageFile = (object.object(forKey: "ImageFile") as? PFFile)
imageFile?.getDataInBackground (block: { (data, error) -> Void in
if error == nil {
if let imageData = data {
//Here you can cast it as a UIImage or do what you need to
self.fullImage.image = UIImage(data:imageData)
}
}
})
这篇关于如何从 Parse 检索图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!