Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios7 PHImageManager请求ImageForAsset:不工作_Ios7_Photos - Fatal编程技术网

Ios7 PHImageManager请求ImageForAsset:不工作

Ios7 PHImageManager请求ImageForAsset:不工作,ios7,photos,Ios7,Photos,我有一个组织文字笔记的应用程序。我正在添加允许将照片添加到UITextView便笺的功能。我添加了一个子类UICollectionViewController,用于向用户展示一张照片,用户可以从中选择一张照片插入便笺 下面的UICollectionView委托方法用于用照片填充集合视图。我已经测试了这个视图控制器,使用应用程序桌面图标作为“photoImage”的测试图像,一切正常 - (UICollectionViewCell *)collectionView:(UICollectionVie

我有一个组织文字笔记的应用程序。我正在添加允许将照片添加到UITextView便笺的功能。我添加了一个子类UICollectionViewController,用于向用户展示一张照片,用户可以从中选择一张照片插入便笺

下面的UICollectionView委托方法用于用照片填充集合视图。我已经测试了这个视图控制器,使用应用程序桌面图标作为“photoImage”的测试图像,一切正常

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PHAsset *asset = (PHAsset *)[fetchResult objectAtIndex:indexPath.row];
    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
    options.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat;
    options.synchronous = YES;
    NSLog(@" **** calling requestImageForAsset");
    __block UIImage *photoImage;
    __block dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    (void) [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(80.0,80.0) contentMode:PHImageContentModeAspectFit options:options
                   resultHandler:^(UIImage *img, NSDictionary *info)
                          {
                            NSError *e = [info objectForKey:PHImageErrorKey];
                            NSLog(@" **** error code (%ld), descr (%@)", (long)e.code, e.localizedDescription);
                            NSLog(@" **** img (%p)", img);
                            photoImage = img;
                            dispatch_semaphore_signal(sema);
                          }
          ];
    NSLog(@" **** returned from requestImageForAsset");
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    dispatch_release(sema);
    UIImageView *photoView = [[UIImageView alloc] initWithImage:photoImage];    <=== Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)
    UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"Photo" forIndexPath:indexPath];
    [cell.contentView addSubview:photoView];

    return cell;
}

我的问题是来自requestImageForAsset:call的resultHandler。下面是显示NSLog输出的Xcode日志

2014-12-13 13:18:18.918 iFilebox[23637:866056]****调用请求图像以获取资产2014-12-13 13:18:18.939 iFilebox[23637:866056]
****错误代码0,descr null即使您设置了synchronous,我想知道它是否在实际获取您标记为img的结果之前到达您要实例化UIImage photoView的那一行。尝试将img设置为requestImageForAsset的完成块中的cell.backgroundView,看看是否有效

另外,也许这只是一种偏好,但我会先实例化您的单元格,然后再执行任何操作。事实上,您可能希望对单元格进行子类化,并在子类中设置图像