I think I'm having a really weird issue here. In some of my TableViews, when I load images from Parse, the cells that don't have any data sometimes displays other images.
The way I have my code is to check for the existence of the file on Parse, and if there is a picture, the PFImageView
loads the image in the background for each cell.
But, if there is no image stored in the database, the PFImageView
is supposed to use a local image that's a placeholder. However, often in my PFTableView
, the cells without image data take on images from other cells. Does anyone have any idea why? Or know of a fix?
Here's the code:
if business["businessImage"] as? PFFile != nil {
var file: PFFile = business["businessImage"] as PFFile
cell.businessPhoto.file = file
cell.businessPhoto.loadInBackground()
}
else {
cell.businessPhoto.image = UIImage(named: "placeholder user photo")
}
Is it because I'm using loadInBackground()
instead of loadInBackgroundWithBlock()
?
Without using cache, the workaround I found is to first set the image file in cellForRowAtIndexPath
to the placeholder image, and then if the image object was found on the server, the cells image is set to the new file, and then loads it in the background.
Here is the code:
myCell.profilePic.image = UIImage(named: "placeholder user image")
if let file: PFFile = object["profilePicture"] as? PFFile {
myCell.profilePic.file = file
myCell.profilePic.loadInBackground()
}
Thanks everyone for all the help!