Reputation: 21
I am using a UICollectionView with a custom Cell containing one image and one label. I load the data via XML, but I am using a multithread to bind the data of the image in the cells. I am not setting the image to load on the cellForItemAtIndexPath, but I am loading the description from here.
My problem is that the images do not load initially. When I scroll, it does load because I have a method in scrollView:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate)
{
[self loadImagesForOnscreenCells];
}}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self loadImagesForOnscreenCells];
}
I use the following to load the description:
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath; {
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
cell.label.text = xmlPhotosVideosRecordPointer.title;
This is the 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];
}
}
}
}
That being said, is there a way to delegate when the UICollectionView didLoad? This way, I could use [self loadImagesForOnscreenCells]; to refresh the images on screen.
Upvotes: 1
Views: 1063
Reputation: 21
I figured it out and it works! Use:
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
Upvotes: 1