【问题标题】:Images not appearing on first load in PFQueryCollectionViewControllerPF QueryCollection ViewController 中首次加载时未出现图像
【发布时间】:2016-01-04 03:37:03
【问题描述】:

有没有人用 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;


}

【问题讨论】:

    标签: ios objective-c parse-platform pfimageview


    【解决方案1】:

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

    cell.imageView.image = [UIImage imageNamed:@"Icon.png"];
    cell.imageView.file = object[@"icon"];
    [cell.imageView loadInBackground];
    

    【讨论】:

    • 谢谢,但我仍然得到相同的结果:/
    • 我找到了这个但我还没有学 swift stackoverflow.com/a/31270733/5742044
    • 翻译过来就是你必须设置一个占位符图片。但是你的逻辑就是这样做的。您可以在设置后尝试记录图像吗? NSLog(@"%@", cell.imageView.image);
    • 2016-01-04 12:33:00.748 TestApp[4414:169946] (null) 2016-01-04 12:33:00.750 TestApp[4414:169946] (null) 2016-01- 04 12:33:00.751 TestApp[4414:169946] (null) 2016-01-04 12:33:00.751 TestApp[4414:169946] (null) 2016-01-04 12:33:00.752 TestApp[4414:169946] (null) 2016-01-04 12:33:00.753 AeroTV[4414:169946] (null)
    • 那是你设置后的吗?强有力的证据表明imageNamed:@"Icon.png" 不存在,对吧?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 2020-05-06
    • 1970-01-01
    相关资源
    最近更新 更多