如何异步加载图像到
在 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];
}
在 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];
});
请帮我一下,现在加载需要的时间太长了...