我正在使用自定义单元格连接标准UICollectionView。
长话短说,当我重新加载collectionView时,单元格不会按照它们的创建顺序出列。
EX。 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;
}