我正在尝试从PHAsset加载UIImage作为集合视图单元格,如此,
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
myCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CELL_ID" forIndexPath:indexPath];
PHAsset *asset = _assetsFetchResults[indexPath.item];
NSLog(@"asset = %@", asset);
PHImageRequestOptions *myOpts = [[PHImageRequestOptions alloc]init];
myOpts.synchronous = YES;
[_imageManager requestImageForAsset:asset
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeDefault
options:myOpts
resultHandler:^(UIImage *myResult, NSDictionary *myInfo) {
NSLog(@"***---info = %@", myInfo);
cell.myImageView.image = myResult;
}];
return cell;
}
这样运行没有错误,但没有图像发送到单元格,结果处理程序块永远不会被调用。 PHAsset不是零。 TIA
啊!我知道我一定要做些蠢事! 8-)
将此添加到viewDidLoad解决了它。
_imageManager = [[PHCachingImageManager alloc] init];
[self resetCachedAssets];
感谢trungduc和El Tomato让我指向了正确的方向。