Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.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
Iphone UIImageView从核心数据中存储的文件路径加载_Iphone_Objective C_Ios_Uitableview_Uiimageview - Fatal编程技术网

Iphone UIImageView从核心数据中存储的文件路径加载

Iphone UIImageView从核心数据中存储的文件路径加载,iphone,objective-c,ios,uitableview,uiimageview,Iphone,Objective C,Ios,Uitableview,Uiimageview,我已经创建了自己的自定义表视图单元,包括一个数字、一个图像(缩略图)和一个使用核心数据成功存储在sqlite数据库中的内容描述 下图将更好地了解我目前在Interface Builder中拥有的功能: 在之前的屏幕中,我正在存储相机拍摄的图像的文件路径,并将其保存到数据库中。我希望能够在表视图单元格中加载每个UIImageView,并针对每个项存储文件路径 我尝试了以下不起作用的方法: UIImageView * thingPhotoView = (UIImageView *) [ce

我已经创建了自己的自定义表视图单元,包括一个数字、一个图像(缩略图)和一个使用核心数据成功存储在sqlite数据库中的内容描述

下图将更好地了解我目前在Interface Builder中拥有的功能:

在之前的屏幕中,我正在存储相机拍摄的图像的文件路径,并将其保存到数据库中。我希望能够在表视图单元格中加载每个UIImageView,并针对每个项存储文件路径

我尝试了以下不起作用的方法:

UIImageView * thingPhotoView = (UIImageView *)
    [cell viewWithTag:11];

    NSString *path = thing.photo;
    thingPhotoView.image = [UIImage imageWithContentsOfFile:path];

我没有使用
ALAssetLibrary
,但从您使用的URL判断。因此,您需要使用
ALAssetsLibrary
来访问该文件

检查这里的文件

你可能想要这个方法

assetForURL:resultBlock:failureBlock:
看起来像这样

ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];

[library assetForURL:thing.photo
     resultBlock:^(ALAsset *asset) {

         thingPhotoView.image = [UIImage imageWithCGImage:[asset thumbnail]];

     } failureBlock:^(NSError *error) {

       NSLog(@"Couldn't load asset %@ => %@", error, [error localizedDescription]);

     }];

您能否确保
thingPhotoView
path
thing
都不是
nil
。那么你能告诉我们路径的值是多少吗?它们都不是零,路径的值是资产-library://asset/asset.JPG?id=B234919E-4D6F-4042-9731-D86EC0869550&ext=JPGBrilliant,就像一个符咒。我必须将NSURL转换为NSString来存储它,但在显示图像时,使用NSURL*url=[[NSURL alloc]initWithString:thing.photo]再次将其转换回来;