如何將圖像加載到UICollectionview
異步? 裏面下面的方法?將圖像加載到UICollectionView異步?
- (PSTCollectionViewCell *)collectionView:(PSTCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
bookImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", docPath, [[preview objectAtIndex:indexPath.row] lastPathComponent]]];
[[cell grid_image] setImage:bookImage];
}
在viewDidLoad中()我使用下面的非同步調用來加載圖像, 「預覽」 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];
});
請幫me..Now其花費過多時間用於加載...
什麼時間太長特別?圖像大小是多少? – Wain
你應該使[[self collectionView] reloadData];在主線程中。這不是一個答案。它只是評論。 – stosha
使用EGOImageView: https://github.com/enormego/EGOImageLoading –