ActivityIndi​​cator不会在collectionviewcell内停止

时间:2013-03-28 09:20:19

标签: uicollectionview uiactivityindicatorview

我在UITableViewCell中使用UICollectionView在tableviewcell中显示图像。 在后台下载照片时,活动指示器应该是动画的,不显示图像。下载照片后,活动指示器应停止动画并显示照片。 除了第一次显示第一个单元格外,一切正常。显示图像并且活动指示器保持动画。如果我滚动collectionView,它适用于其他图像,当我滚动回第一个图像时,它也可以工作。这是第一次出现第一张图片时

集合视图中的单元格调用PhotoCollectionView,标题如下:

@interface PhotoCollectionCell : UICollectionViewCell

@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;

@end

cellForItemAtIndexPath的代码

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"PhotoCollectionCell";
    PhotoCollectionCell *cell = (PhotoCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.imageView.image = nil;

    UIImage *image = [thumbnails objectForKey:indexPath];
    if(!image) {
        [cell.activityIndicator startAnimating];
        if (self.pictureCollectionView.dragging == NO && self.pictureCollectionView.decelerating == NO)
        {
            [self startDownload:images[indexPath.row] forIndexPath:indexPath];
        }
    } else {
        [cell.activityIndicator stopAnimating];
        cell.imageView.image = image;
    }

    return cell;
}

我在网上尝试了几个解决方案,一切都在主线程上执行,所以我不知道该怎么办了。

帮助将不胜感激。提前致谢。亲切的问候......

0 个答案:

没有答案