嗨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