[英]Load PFFile Into UIImageView in Swift 2.1/Xcode 7.2
I'm really having a hard time trying to get the image to load from Parse... I have it all set up that it sends the image as a file through JavaScript to Parse (see screenshot) and now I'm trying to load the image into my UIImageView in Swift 2.1/Xcode 7.2 Beta. 我真的很难尝试从Parse加载图像...我已经全部设置好了,它通过JavaScript将图像作为文件发送到Parse(请参见屏幕截图),现在我正在尝试加载将图像放入Swift 2.1 / Xcode 7.2 Beta中的UIImageView中。 No errors return and the rest of the app functions like it's supposed to.
没有错误返回,其余的应用程序功能也可以正常运行。 I cannot seem to get it working, though.
不过,我似乎无法正常工作。 Any help would be much appreciated.
任何帮助将非常感激。
let currentUser = PFUser.currentUser()
if currentUser != nil {
if let companyImage = currentUser!["pic"] as? PFFile {
companyImage.getDataInBackgroundWithBlock({ ( imageData: NSData?, error: NSError?) -> Void in
if error == nil{
self.pic.image = UIImage(data: imageData!)
} else {
print("No image found")
}
})
}
Here's a screenshot of what shows up in Parse after I save it through a website I created with JavaScript 这是我通过使用JavaScript创建的网站将其保存后在Parse中显示的内容的屏幕截图
Edit: 编辑:
I have also edited the Info.plist file in my app to make sure that requests made to the internet could be handled, and it worked because I was able to load the user's username. 我还编辑了我的应用程序中的Info.plist文件,以确保可以处理对Internet的请求,并且它可以工作,因为我能够加载用户的用户名。
i don't think the current user contains other object than the default.To be sure make sure you have the user data of the row. 我不认为当前用户包含默认对象以外的其他对象。请确保您具有该行的用户数据。 so try this
所以试试这个
var query = PFUser.query()
query.whereKey("objectId", equalTo: PFUser.currentUser().objectId)
query.findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
print("Successfully retrieved \(objects!.count) scores.")
// Do something with the found objects
if let objects = objects {
if let companyImage = objects[0]!["pic"] as? PFFile {
companyImage.getDataInBackgroundWithBlock({ ( imageData: NSData?, error: NSError?) -> Void in
if error == nil{
self.pic.image = UIImage(data: imageData!)
} else {
print("No image found")
}
})
}
} else {
// Log details of the failure
print("Error: \(error!) \(error!.userInfo)")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.