2

有没有人得到一个 PFQueryCollectionViewController 来用 Objective C 加载图像?

当用户第一次加载视图时,它将加载文本,而不是图像。用户第二次加载视图时,图像被加载。我不明白。

- (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;


}
4

1 回答 1

0

该行为与 imageView.image 最初为非零一致。只需无条件地执行占位符分配。一旦图像被缓存,占位符将被真实图像的分配撤消(在绘制任何东西之前)......

cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
cell.imageView.file = object[@"icon"];
[cell.imageView loadInBackground];
于 2016-01-04T03:46:03.650 回答