我正在使用自定义的UICollectionViewCell编码UICollectionView,以允许更新进度。但是当我打电话给cellForItemAtIndexPath:[NSIndexPath indexPathForItem:3 inSection:0]
时,返回的单元格可以是随机的。
[self.collectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell" bundle:nil] forCellWithReuseIdentifier:CollectionViewCellId];
// [self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:CollectionViewCellId];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
percentage += 0.1;
CollectionViewCell *item = (CollectionViewCell*)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:3 inSection:0]];
if (item) {
// if (self.collectionView.reloaded) {
[item.progressView setProgress:percentage];
// [self.collectionView reloadData];
// }
if (reloaded) {
reloaded = NO;
[self reloadDataAndWait:^{
reloaded = YES;
}];
}
}
}] ;
代码项目是附加文件。 https://github.com/muhku/FreeStreamer/files/2247985/CollectionView.zip