gpt4 book ai didi

ios - 无法将 PFFile 转换为 UIImage

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:14:49 25 4
gpt4 key购买 nike

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

我有一个 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()?.profileImageNOT NIL
  2. getDataInBackgroundWithBlock 函数未返回错误
  3. 但是数据总是

关于我做错了什么的想法?

谢谢!!

最佳答案

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

 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
}
}

关于ios - 无法将 PFFile 转换为 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30914876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com