カスタムセルを使用して標準の UICollectionView を接続しています。
要するに、collectionView をリロードすると、セルは作成された順序でキューから取り出されません。
元。indexPath.row 5 のセルは、indexPath.row 0 に返されます。
これにより、collectionView をリロードするとフラッシュが発生します。collectionView をリロードするときに同じセルを再利用したいのですが、データが同じであればリロードしたくありません。順序が間違っているため、同じになることはありません。
他の誰かがこれに悩まされていますか、それとも修正していますか? UITableView はこれを行いません。同じ順序でセルを使用します。collectionView はなぜそうしないのですか?
- (id)initWithUser:(User *)user andCollectionView:(UICollectionView *)collectionView {
if (self = [super initWithCollectionView:collectionView]) {
_collectionView = collectionView;
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.showsVerticalScrollIndicator = YES;
_collectionView.pagingEnabled = NO;
_collectionView.bounces = YES;
_collectionView.alwaysBounceVertical = YES;
[_collectionView registerClass:[SubmissionMinimalCollectionViewCell class]
forCellWithReuseIdentifier:SubmissionCollectionCellIdentifier];
UIEdgeInsets scrollInsets = self.collectionView.scrollIndicatorInsets;
scrollInsets.right = 1;
_collectionView.scrollIndicatorInsets = scrollInsets;
__weak typeof(self) weakSelf = self;
self.data = [self.user fetchSubmissionsByPage:self.pageCount
objectsPerPage:self.perPage
andForceRefresh:YES
withCompletion:^(NSArray *submissions) {
weakSelf.pageCount++;
weakSelf.data = submissions;
[weakSelf.collectionView reloadData];
}];
[self.collectionView reloadData];
}
return self;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
SubmissionMinimalCollectionViewCell *cell = [self.collectionView
dequeueReusableCellWithReuseIdentifier:SubmissionCollectionCellIdentifier
forIndexPath:indexPath];
[cell prepareForUseWithSubmission:[self.data objectAtIndex:indexPath.row]];
cell.row = indexPath.row;
return cell;
}