カバー フローをシミュレートするようなコレクション ビューがあります。このように ALAssetLibrary から非同期に画像を読み込みます。
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
myCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CELL_ID" forIndexPath:indexPath];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
ALAsset *asset = [assets objectAtIndex:indexPath.row];
CGImageRef thumbnailImageRef = [[asset defaultRepresentation]fullScreenImage];
UIImage *thumbnail = [UIImage imageWithCGImage:thumbnailImageRef];
dispatch_async(dispatch_get_main_queue(), ^{
cell.myImageView.image = thumbnail;
});
});
return cell;
}
ユーザーがすばやくスクロールすると、画像の読み込みに時間がかかります。ユーザーが画像 20 にすばやくスクロールすると、画面に表示されなくなっても、画像 1 ~ 19 が読み込まれるまで待たなければならないと考えています。それで、私の質問は、読み込みプロセスが完了する前にセルが画面外に移動した場合、画像の読み込みを停止する方法はありますか?