【问题标题】:Unable to Convert PFFile to UIImage无法将 PFFile 转换为 UIImage
【发布时间】:2015-09-04 01:31:15
【问题描述】:

我想知道我是否在这里做错了什么。

我有一个PFUser 的子类,它的属性为profileImage,即PFFile

在某些情况下,我不会立即将 profileImage 保存到 Parse,而仅将其固定到 localDatastore

但是当我尝试从localDataStore 取回它并使用getDataInBackgroundWithBlock 时。它不会返回任何错误,但是回调返回的 NSData总是 nil

if let profileImage = PGUser.currentUser()?.profileImage {
    profileImage.getDataInBackgroundWithBlock { (data: NSData?, error: NSError?) -> Void in
        if error == nil {
            if  data != nil {
                println("IMAGE DATA FOUND")
                let image = UIImage(data: data!);
                self.profileImageView.image = image;
            }
            else {
                //DATA IS ALWAYS NIL    
                println("NO IMAGE DATA FOUND")
            }
        }
    }

}
  1. PGUser.currentUser()?.profileImage 不为零
  2. getDataInBackgroundWithBlock 函数没有返回错误
  3. 但是 数据 总是

对我做错了什么有什么想法吗?

谢谢!!

【问题讨论】:

  • error 告诉你什么?
  • 问题是数据总是nil。 getDataInBackgroundWithBlock 中的数据。这可能是什么原因造成的?
  • 我不知道,也许error 参数可以说明情况
  • 错误为零。但数据也是零
  • 记录文件URL,看看你是否可以在浏览器中访问它。上传时有错误吗?

标签: ios parse-platform uiimage pfobject pffile


【解决方案1】:

试试这个。我用这个解决了我的问题

 let profileImage = userPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if !error {
    let image = UIImage(data:imageData)
self.profileImageView.image = image
 }
}

【讨论】:

  • 这段代码不会编译,因为参数是'(NSData?, NSError?)',在我改成那个之后,数据仍然是nil
猜你喜欢
  • 2015-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-19
  • 2017-05-07
  • 1970-01-01
  • 2017-05-08
相关资源
最近更新 更多