![](/img/trans.png)
[英]Swift 2, Xcode 7.2 'NSInternalInconsistencyException
[英]Load PFFile Into UIImageView in Swift 2.1/Xcode 7.2
我真的很難嘗試從Parse加載圖像...我已經全部設置好了,它通過JavaScript將圖像作為文件發送到Parse(請參見屏幕截圖),現在我正在嘗試加載將圖像放入Swift 2.1 / Xcode 7.2 Beta中的UIImageView中。 沒有錯誤返回,其余的應用程序功能也可以正常運行。 不過,我似乎無法正常工作。 任何幫助將非常感激。
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")
}
})
}
這是我通過使用JavaScript創建的網站將其保存后在Parse中顯示的內容的屏幕截圖
編輯:
我還編輯了我的應用程序中的Info.plist文件,以確保可以處理對Internet的請求,並且它可以工作,因為我能夠加載用戶的用戶名。
我不認為當前用戶包含默認對象以外的其他對象。請確保您具有該行的用戶數據。 所以試試這個
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.