[英]UIImageView load from file path stored in Core Data
我创建了自己的自定义表格视图单元格,包括数字,图像(缩略图)以及使用Core Data成功存储在sqlite数据库中的内容的描述。
下面的图片将更好地了解我目前在Interface Builder中拥有的内容:
在之前的屏幕中,我存储了用相机拍摄的图像的文件路径并将其保存到数据库中。 我希望能够在Table View Cells上加载每个UIImageView,并为每个项目存储文件路径。
我尝试了以下不起作用:
UIImageView * thingPhotoView = (UIImageView *)
[cell viewWithTag:11];
NSString *path = thing.photo;
thingPhotoView.image = [UIImage imageWithContentsOfFile:path];
我没有使用ALAssetLibrary
而是根据您正在使用的URL来判断。 因此,您需要使用ALAssetsLibrary
来访问该文件
检查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]);
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.