Has anyone ever gotten a PFQueryCollectionViewController to load images with Objective C?
When the user first loads the view it will load the text, but not the images. The second time the user loads the view, the images are loaded. I do not understand.
- (PFCollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object {
PFCollectionViewCell *cell = [super collectionView:collectionView cellForItemAtIndexPath:indexPath object:object];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.text = object[@"name"];
cell.imageView.file = object[@"icon"];
// If the image is nil - set the placeholder
if (cell.imageView.image == nil) {
cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
[cell.imageView loadInBackground];
}
cell.contentView.layer.borderWidth = 1.0f;
cell.contentView.layer.borderColor = [UIColor clearColor].CGColor;
return cell;
}
The behavior is consistent with the imageView.image being non-nil initially. Just perform the placeholder assignment unconditionally. Once the image is cached, the placeholder will be undone by the assignment of the real image (before anything is drawn)...
cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
cell.imageView.file = object[@"icon"];
[cell.imageView loadInBackground];