Hi everyone,
I have the following problem with loading an image in a cocoa/ obj c application.
Code that works:
NSImage *photoImage = [[NSImage alloc] initWithContentsOfFile"/Users/oana/Project/pagePhoto.jpg"];
Code that doesn't work:
NSString imageName = [[NSBundle mainBundle] pathForResource"pagePhoto" ofType"jpg"];
//NSImage *photoImage = [[NSImage alloc] initWithContentsOfFile:imageName];
//no point in calling the previus line since imageName is allways nil in my case
I have added pagePhoto.jpg to the Resources folder in xcode, and I can see it in the build directory, in the resources.
What have I missed? Why only absolute path works and I cannot load the image from resources?
Thank you for your replies!
I have the following problem with loading an image in a cocoa/ obj c application.
Code that works:
NSImage *photoImage = [[NSImage alloc] initWithContentsOfFile"/Users/oana/Project/pagePhoto.jpg"];
Code that doesn't work:
NSString imageName = [[NSBundle mainBundle] pathForResource"pagePhoto" ofType"jpg"];
//NSImage *photoImage = [[NSImage alloc] initWithContentsOfFile:imageName];
//no point in calling the previus line since imageName is allways nil in my case
I have added pagePhoto.jpg to the Resources folder in xcode, and I can see it in the build directory, in the resources.
What have I missed? Why only absolute path works and I cannot load the image from resources?
Thank you for your replies!