【问题标题】:UICollectionViewCell will not find Custom Cell to load imageUICollectionViewCell 将找不到自定义单元来加载图像
【发布时间】:2012-10-17 04:46:44
【问题描述】:

我正在使用 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];刷新屏幕上的图像。

【问题讨论】:

    标签: xcode xcode4 xcode4.5 uicollectionview uicollectionviewcell


    【解决方案1】:

    我想通了,它有效!使用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多