Problems starting UIImage with image path coming from core data

0

I downloaded an image, and I stored it on disk. After downloading the class inserts the image path in the core data, getting this string:

@"/Users/Tiago/Library/Developer/CoreSimulator/Devices/3E103B07-E48E-4740-911C-ECD24E0C3A3F/data/Containers/Data/Application/D17A1BA1-7096-49F9-BDAD-9587B2780715/Documents/54bf3ebf657f6f2c04a81b0b.jpg
"

However at the time of loading this image into a UIImage it is started with nil, as shown in the code below:

// Implementação de uma UITableView.
...

    NSManagedObject *device = [dadosRetornadosDoCoreData objectAtIndex:indexPath.row];
...
    NSString* stringPath = [device valueForKey:@"imagempath"];
    UIImage* imageNew = [[UIImage alloc]initWithContentsOfFile:stringPath];
    [cell.imagemProduto setImage:imageNew];
    return cell;

I added an image to the project, and I loaded it as the code below:

UIImage* imageNew = [[UIImage imageNamed:@"cloud.png"];

And loaded normally.

Detail: The String leading to the image is coming from the Core Data store. I do not know if this can affect String interpretation.

    
asked by anonymous 31.01.2015 / 23:03

1 answer

0

As recommended by your friend Paulo Rodrigo, the folders path can be changed as per updates in the App. It may not be found.

Then I made changes only to store the name of the image in Core Data, and to recover this image, I execute the following code:

    NSArray* caminhos = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
NSUserDomainMask, YES);
    NSString* pastaDeDocumentos = [caminhos objectAtIndex:0];
    NSManagedObject *dadosCoreData = [dadosRetornadosDoCoreData objectAtIndex:0];
    NSString* stringPathImage = [NSString stringWithFormat:@"%@/%@",pastaDeDocumentos,[dadosCoreData valueForKey:@"imagempath"]];
    UIImage* imageNew = [UIImage imageWithContentsOfFile:stringPathImage];
    
01.02.2015 / 13:50