簡體   English   中英

UIImageView從存儲在Core Data中的文件路徑加載

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM