views:

49

answers:

1

Hello,

I have the following code in place:

- (void)viewDidLoad {
    NSString *homeDirectoryPath = NSHomeDirectory();
    NSString *imagePath = [homeDirectoryPath stringByAppendingString:@"/graph.png"];
    NSLog(@"Image: %@", imagePath);

    if (![[NSFileManager defaultManager] fileExistsAtPath:imagePath isDirectory:NULL]) 
    {
        graph = imagePath;
        //[[NSFileManager defaultManager] createDirectoryAtPath:imagePath attributes:nil];
    }

'graph' is defined as UIImageView. I'm trying to display the file in the path 'imagePath'. I know the code graph = imagePath is not correct, as the variable 'imagePath' states it contains the path to the image.

How would I display my image located at the specific image path ?

Regards, Stephen

+1  A: 

You'll have to create an imageview object, set it as the image view's image and release the image you created:

UIImage *graphImage = [[UIImage alloc] initWithContentsOfFile: imagePath];
graph.image = graphImage;
[graphImage release];
lukya
Thanks for the answer, but what's the purpose of the initContentsOfFile method ?
Stephen
I'm getting errors with initContentsOfFile, but when I use initWithContentsOfFile, it compiles cleanly, but still doesn't display the image.
Stephen
Anybody else any thoughts on this ????
Stephen
sorry.. my bad. it was a typo i meant to type initWithContentsOfFile. i've corrected it in the answer. initWithContentsOfFile should work as long as the image path is correct.
lukya
Thanks Lukya, image is still not displaying as expected, when I display my imagePath in the log file, I get '/Users/stephenconnolly/Library/Application Support/iPhone Simulator/3.1.3/Applications/261904F9-AF97-4C5C-A968-0E51CDD2CD71/Documents/graph.png'. Graph.png exists at this location so I'm not sure whats happening.
Stephen
try it on device... the simulator acts weird sometimes.
lukya
All sorted Lukya, thanks...the last problem was actually with the graph.png file, so I just fixed this and the code above works like a charm.Thanks again.
Stephen