我想知道是否有人可以帮助我,我是应用程序开发的新手 我正在从我的应用程序上传图像以在解析文档的帮助下毫无问题地解析。
let imageData = UIImagePNGRepresentation(scaledImage)
let imageFile: PFFile = PFFile(data: imageData)
var userPhoto = PFObject(className: "postString")
userPhoto["imageFile"] = imageFile
userPhoto.saveInBackground()
但是当我添加代码来检索图像时,我有点迷路了:/
let userImageFile = anotherPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if !error {
let image = UIImage(data:imageData)
}
}
“anotherPhoto”来自哪里? Parse 确实说“这里我们从另一个名为 anotherPhoto 的 UserPhoto 中检索图像文件:”
最佳答案
anotherPhoto
将是您的 postString
的实例(在您的上传示例中为 userPhoto
)。适合您的文件下载示例如下:
let userImageFile = userPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if !error {
let image = UIImage(data:imageData)
}
}
任何 PFFile 都必须从普通 PFObject 中引用,否则无法检索。 PFFile 对象本身不会显示在数据浏览器中。
关于ios - 如何快速从解析中加载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24717302/