Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have a UICollectionView that while scroll in occasions stops updating cells. It load a few cells but when I scroll down or up the rest of the UIcollectionView is empty although the contensize is bigger that the few cells visibles sizes.

It happens more when I scroll really fast, randomly cellForItemAtIndexPath stops being called and the UICollectionView only shows the last loaded cells, with the rest of the space 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 mark 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 mark UICollectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.item == self.newsArray.count - 1) {
    [self addMoreNews]; // add items to array and call collection reloaddata
}
}

pragma mark 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));
}
share|improve this question
    
Did you check by assign only color with your cell? Because some time issue in cell data – Hindu Jul 18 '15 at 10:02
    
Yes, showing only cells with background color without data have the same issue – principeroxido Jul 18 '15 at 10:18
    
That's great so you just need to check your data for cells which are not showing proper data and issue will solved – Hindu Jul 18 '15 at 10:20
    
It's not the data. After scroll for some time, cellForItemAtIndexPath stops being called and only are visible the cells that were in screen before this happen. When scroll for the uicollectionview only these cells are displaying, the rest are missing. – principeroxido Jul 18 '15 at 10:45
    
Can you provide your sample Xcode project or you need to check your new data function. From you are adding, new items in collection view. – Hindu Jul 19 '15 at 10:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.