【发布时间】:2013-08-03 08:38:33
【问题描述】:
如何将图像异步加载到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];
});
请帮帮我..现在加载时间太长了...
【问题讨论】:
-
具体是什么时间太长了?图片的尺寸是多少?
-
你应该做这个 [[self collectionView] reloadData];在主线程中。这不是一个答案。这只是评论。
-
使用 EGOImageView : github.com/enormego/EGOImageLoading
标签: ios objective-c asynchronous uicollectionview