有没有人有过使用Objective C加载图片的PFQueryCollectionViewController?
当用户首次加载视图时,它将加载文本,但不加载图像。用户第二次加载视图时,会加载图像。我不明白。
- (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;
}
答案 0 :(得分:0)
行为与最初非nil的imageView.image一致。只需无条件地执行占位符分配。缓存图像后,占位符将通过分配实际图像(在绘制任何内容之前)撤消...
cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
cell.imageView.file = object[@"icon"];
[cell.imageView loadInBackground];