Search code examples
iphoneiosxcodexcode4asihttprequest

How to call the local image file and display into the imageviewcontroller


I create the one application in that create the locally store the file in payment while the application not be deleted.

This I have done: I download the file and store into locally (applications document folder).

Now I am having trouble with this: While the after the image is downloaded then I fetch into locally and that image will not display. In NSLog following url is generated and i can't display the image.

/Users/username/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/F233ED88-1546-4FB0-BE93-0E0FB8C8C3D6/Documents/NationalMedalofArts-150x150.jpg

Edit:

NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",
                   @"/Users/username/Library/Application Support/iPhone Simulator/5.0/Applications/F233ED88-1546-4FB0-BE93-0E0FB8C8C3D6/Documents/NationalMedalofArts-150x150.jpg"]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
NSLog(@"%@",imageData);
UIImage *image = [UIImage imageWithData:imageData];
self.imgView.image = image;

when the NSLog the NSData then it's NULL to display


Solution

  • This is better:

    NSString *fileName = @"NationalMedalofArts-150x150.jpg";
    NSString *path = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(), fileName];
    self.imgView.image = [UIImage imageWithContentsOfFile:path];