UICollectionViewCell将找不到自定义单元格来加载图像

时间:2012-10-26 22:03:53

标签: xcode xcode4 xcode4.5 uicollectionview uicollectionviewcell

我正在使用带有一个包含一个图像和一个标签的自定义Cell的UICollectionView。我通过XML加载数据,但我使用多线程来绑定单元格中图像的数据。我没有将图像设置为加载到cellForItemAtIndexPath,但我从这里加载描述。

我的问题是图像最初没有加载。当我滚动时,它会加载,因为我在scrollView中有一个方法:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { 
if (!decelerate)
{
    [self loadImagesForOnscreenCells];
}}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{      
    [self loadImagesForOnscreenCells];   
}

我使用以下内容加载说明:

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath; { 
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
cell.label.text = xmlPhotosVideosRecordPointer.title;

这是loadImagesForOnscreenCells:

- (void)loadImagesForOnscreenCells
{
if ([xmlPhotosVideosRecords count] > 0)
{
    NSArray *visiblePaths = [newsTable indexPathsForVisibleItems];
    for (NSIndexPath *indexPath in visiblePaths)
    {            
        xmlPhotosVideosRecord *xmlPhotosVideosRecordPointer = [self.xmlPhotosVideosRecords objectAtIndex:indexPath.row];

        if (!xmlPhotosVideosRecordPointer.thumbImage)
        {
            [self startIconDownload:xmlPhotosVideosRecordPointer forIndexPath:indexPath];
        }
    }  
}
}

话虽如此,有没有办法在UICollectionView didLoad时委托?这样,我可以使用     [self loadImagesForOnscreenCells];刷新屏幕上的图像。

1 个答案:

答案 0 :(得分:1)

我想出来了,它的确有效!使用:

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath