2

I have a UICollectionView with a UICollectionViewFlowLayout that I'm using essentially as a UITableView. I'm not using a UITableView because there is some custom functionality that we needed that isn't possible with a table view.

When the list gets long (~150+ items) the collectionview starts presenting cells strangely while scrolling. Instead of loading them one at a time while you scroll, they get loaded in batches. This results in a temporarily blank view while scrolling, and if you scroll all the way to the bottom items will be missing (because you could not scroll down far enough for them to load). I've only tried this with iOS 8.

The effect is something akin to the one shown in this question, except that this happens for up to an entire page of cells and during scrolling instead of during a delete animation.

Also, prepareForReuse is only occasionally being called. I checked to make sure that Accessibility is not getting in the way by disabling all accessibility settings, but that was not the problem.

Here's the code, but it's just a standard UICollectionView with flow layout implementation so I'm not sure if it will be useful:

- (void)configureCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];

    collectionView.alwaysBounceVertical = YES;
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.backgroundColor = [UIColor clearColor];
    collectionView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.collectionViewContainer addSubview:collectionView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    id<SectionInfo> sectionInfo = [self.collectionList.sections objectAtIndex:section];
    return sectionInfo.numberOfObjects;
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    id object = [self.collectionList objectAtIndexPath:indexPath];
    UICollectionViewCell *cell = nil;
    if ( [object isKindOfClass:[CustomListItem class]] ) {
        CustomItemCell *cCell = [collectionView dequeueReusableCellWithReuseIdentifier:[CustomItemCell reuseIdentifier] forIndexPath:indexPath];
        [cCell setItem:object];
        cell = cCell;
    }
    return cell;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return [self.collectionList.sections count];
}

Has anyone seen a similar issue? Have any ideas?

Community
  • 1
  • 1
poff
  • 1,640
  • 15
  • 16

0 Answers0