Images not appearing in PFQueryCollectionViewController

£可爱£侵袭症+ 提交于 2019-12-03 21:42:06

My co-developer finally found the answer to this. We had to set a placeholder image for the PFImageViews when configuring the cells in cellForItemAtIndexPath. The code examples on Parse do include setting the placeholder image, but they don't say that it is required for the PFQueryCollectionViewController to work properly. We considered it an aesthetic touch that we could come back to later.

So the answer is: in order for images to load properly in the cells of a PFQueryCollectionViewController you MUST provide a placeholder image when configuring the cells in cellForItemAtIndexPath.

Here's the code that worked:

let placeholder = UIImage(named: "myPlaceholderImage")  //an image from images.xcassets in your xcode project
cell.imageView.image = placeholder

if let pfObject = object {
    cell.imageView.file = pfObject["image"] as? PFFile
    cell.imageView.loadInBackground()
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!