嗨iam使用PST Collectionview
类似UIcollectionview
。我想从我的文档目录加载图像集合view.First尝试同步的方式,但它太慢..所以知道我怎么能异步加载图像到collectionview。异步图像加载不起作用?
我添加以下代码,以便将图像下载到我的文档目录
dispatch_queue_t imageLoadQueue = dispatch_queue_create("com.aaa.nkp",NULL);
dispatch_async(imageLoadQueue, ^{
usleep(1000000);
docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
for(int i=0; i <[Images count] ;i++){
imgURL = [Images objectAtIndex:i];
[imagePreview addObject:imgURL];
imgData=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgURL]];
[imgData writeToFile:[NSString stringWithFormat:@"%@/%@", docPath, [imgURL lastPathComponent]] atomically:YES];
}
[[self collectionView] reloadData];
});
和的CollectionView cellforitem()内梅索德
- (PSTCollectionViewCell *)collectionView:(PSTCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
cell = nil;
cell = (GMMCollectionViewCell *)[self.collectionView dequeueReusableCellWithReuseIdentifier:@"test" forIndexPath:indexPath];
cell.tag = indexPath.row;
docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
BOOL isImageLoaded = YES;
bookImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", docPath, [[Images objectAtIndex:indexPath.row] lastPathComponent]]];
if(bookImage == nil)
isImageLoaded = NO;
if(!isImageLoaded){
[[cell grid_image] setImage:[UIImage imageNamed:@"Placeholder.png"]];
}
else{
[[cell grid_image] setImage:bookImage ];
}
return cell;
}
你是如何尝试异步加载图像的? – Wain
@navi直接在图像载入“UIImageView” –
我只是试图从该文件目录加载图像。我没有添加任何代码,但我怎么能从那里加载图像异步collectionview? – Navi