尝试使用Swift从Parse显示图像时出现问题

编程入门 行业动态 更新时间:2024-10-22 16:19:08
本文介绍了尝试使用Swift从Parse显示图像时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用swift显示来自解析的图像.这是我的代码:

I am trying to display an image from parse using swift. This is my code:

var query = PFQuery(className: "Maps") query.getObjectInBackgroundWithId("1234asdf3456") { (object: PFObject?, error: NSError?) -> Void in if error == nil { println(object) var objectAsPF = object as PFObject! let file = objectAsPF["imageFile"] as! PFFile file.getDataInBackgroundWithBlock { (imageData:NSData?, error:NSError?) -> Void in if error == nil { if let imageData = imageData { let map:UIImage = UIImage(data: imageData)! self.MapView.image = map println("success") } } } } else { println(error) } }

我在println("success")处设置了一个断点,并检查了变量值,一切都很好,直到我尝试将imageData转换为UIImage为止.有提示吗?

I set a breakpoint at println("success") and i checked the variable values and everything is fine until i try to convert imageData to UIImage. Any tips?

推荐答案

使用此代码从解析中撤消图像,然后将其从PFFile转换为UIImage ...

Use this code to retreave images from parse then convert it from a PFFile to a UIImage...

var query = PFQuery(className:"Maps") query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in if error == nil { // The find succeeded. self.scored = objects!.count // Do something with the found objects if let objects = objects as? [PFObject] { for object in objects { let userImageFile = object["imageFile"] as! PFFile userImageFile.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in if error == nil { if let imageData = imageData { let image = UIImage(data:imageData) if image != nil { self.imageArray.append(image!) } } } } } } } else { // Log details of the failure println("Error: \(error!) \(error!.userInfo!)") } dispatch_async(dispatch_get_main_queue()) { println("Finished Loading Image") }

更多推荐

尝试使用Swift从Parse显示图像时出现问题

本文发布于:2023-10-04 08:18:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467139.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   Swift   Parse

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!