1

1 つの画像と 1 つのラベルを含むカスタム セルで 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 が Load されたときに委任する方法はありますか? このように、[self loadImagesForOnscreenCells]; を使用できます。画面上の画像を更新します。

4

1 に答える 1

1

私はそれを理解しました、そしてそれはうまくいきます!使用する:

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
于 2012-10-27T21:56:10.720 に答える