UICollectionview
に画像を非同期で読み込むにはどうすればよいですか? 以下の方法はありますか? のviewDidLoad()でイメージをUICollectionViewに非同期で読み込みますか?
- (PSTCollectionViewCell *)collectionView:(PSTCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
bookImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", docPath, [[preview objectAtIndex:indexPath.row] lastPathComponent]]];
[[cell grid_image] setImage:bookImage];
}
私はそののロードのためにあまりにも多くの時間を取ってme..Now助けてください "プレビュー" NSMutablearray
dispatch_queue_t imageLoadQueue = dispatch_queue_create("com.GMM.assamkar", NULL);
dispatch_async(imageLoadQueue, ^{
//Wait for 5 seconds...
usleep(1000000);
docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
for(int k=0; k <[allImage count] ;k++){
imgURL = [allImage objectAtIndex:k];
[imagePreview addObject:imgURL];
imgData=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgURL]];
[imgData writeToFile:[NSString stringWithFormat:@"%@/%@", docPath, [allImage lastPathComponent]] atomically:YES];
}
[[self collectionView] reloadData];
});
に画像をロードするには、次の非同期呼び出しを使用しています...
特に時間がかかりすぎて何?画像のサイズは? – Wain
これを[[self collectionView] reloadData]にする必要があります。メインスレッド。それは答えではありません。コメントだけです。 – stosha
を使用するEGOImageView: https://github.com/enormego/EGOImageLoading –