【问题标题】:requestImageForAsset resultHandler block never gets calledrequestImageForAsset resultHandler 块永远不会被调用
【发布时间】:2018-09-15 02:57:17
【问题描述】:

我正在尝试从 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

【问题讨论】:

  • 你确定 _imageManager 不是 nil 吗?
  • 什么是_imageManager,它从何而来?

标签: objective-c uicollectionview uiimage uikit phasset


【解决方案1】:

啊!我知道我一定是在做一些愚蠢的事情! 8-)

将此添加到 viewDidLoad 解决了它。

_imageManager = [[PHCachingImageManager alloc] init];
[self resetCachedAssets];

感谢 trungduc 和 El Tomato 为我指明了正确的方向。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-27
    • 2013-10-12
    • 2012-03-27
    • 2013-08-29
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    相关资源
    最近更新 更多