[英]Swift 2.0:Need to display image(PFFile) on PFQueryTableViewController from Parse?
[英]Swift 2.0 Parse PFFile/Image
我有一個使用Parse存儲個人資料照片的Swift項目。 出於某種原因,PFFile配置文件映像很難上班。 我終於在Swift 1.2中使用此功能使它工作:
func image(completion: (image: UIImage) -> Void)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
if self.profilePictureImage == nil
{
if self.profilePicture != nil
{
self.fetchIfNeeded()
if let data = self.profilePicture!.getData()
{
self.profilePictureImage = UIImage(data: data)
}
}else
{
self.profilePictureImage = UIImage(named: "no_photo")!
}
}
dispatch_async(dispatch_get_main_queue(),{
completion(image: self.profilePictureImage)
})
})
}
profilePicture
是@NSManaged PFFile
profilePictureImage' is an
內部UIImage`
我已將項目遷移到Swift 2.0,並且在completion
調用時因未包裝的nil錯誤而崩潰。
有什么變化? 我該如何解決? 謝謝!
首先,檢查ParseUI
框架,該框架包括PFImageView
類,用於自動處理PFImageView
的下載和顯示。
創建出口
@IBOutlet weak var profilePictureImage: PFImageView!
典型用法
// Set placeholder image
profilePictureImage.image = UIImage(named: "no_photo")
// Set remote image (PFFile)
profilePictureImage.file = profilePicture
// Once the download completes, the remote image will be displayed
profilePictureImage.loadInBackground { (image: UIImage?, error: NSError?) -> Void in
if (error != nil) {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
} else {
// profile picture loaded
}
}
除此之外,由於iOS9對應用程序傳輸安全性的更改,最近有大量帖子發布,人們遇到PFFile.getData()
在Swift2中不起作用的問題。 根據解析,此問題已在最新的SDK中修復
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.