UICollectionView在快速滚动后不显示单元格
我有一个UICollectionView,在滚动的情况下停止更新单元格。 它加载了几个单元格,但是当我向下滚动或向上滚动时,UIcollectionView的其余部分是空的,尽管比例较大,几个单元格的大小可见。
当我滚动得非常快时,发生的情况会更多,随机调用cellForItemAtIndexPath并且UICollectionView只显示最后加载的单元格,其余空格为空。
这是我的代码:
[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])];
编注标记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;
}
编译标记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
}
}
编注标记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));
}
链接地址: http://www.djcxy.com/p/91645.html
上一篇: UICollectionView not displaying cells after fast scroll
下一篇: Cells insight UICollectionView do not load until there are visible?