I have a UICollectionView that when scrolling in cases stops the cell updating. It loads a few cells, but when I scroll down or up, the rest of the UIcollectionView is empty, although contensize more than a few cells see dimensions.
This happens more often when I scroll very fast, at random the cellForItemAtIndexPath ceases to be called, and the UICollectionView shows only the last loaded cells, and the rest of the space is empty.
Here is my code:
[self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([NewsCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([NewsCollectionViewCell class])];
[self.collectionView registerClass:[NewsHeaderCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([NewsHeaderCollectionReusableView class])];
pragma sign UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return self.newsArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NewsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([NewsCollectionViewCell class]) forIndexPath:indexPath];
[cell refreshWithContentModel:self.newsArray[indexPath.item]];
return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath
{
NewsHeaderCollectionReusableView *collectionReusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([NewsHeaderCollectionReusableView class]) forIndexPath:indexPath];
if (self.newsArray.count) {
[collectionReusableView refreshWithContentModel:self.newsArray[0]];
}
return collectionReusableView;
}
pragma sign UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.item == self.newsArray.count - 1) {
[self addMoreNews];
}
}
pragma sign UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(ceilf(self.collectionView.bounds.size.width / 3.0) - 10, ceilf(self.collectionView.bounds.size.height / 3.0));
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
return CGSizeMake(self.collectionView.bounds.size.width, ceilf(self.collectionView.bounds.size.height / 2.0));
}
source
share