views:

1186

answers:

1

How come I can load a local xml file from the main bundle, but I can't load images?

NSString *path = [[NSBundle mainBundle] resourcePath];

This gets loaded (i know because I can trace it) /Users/me/Library/Application Support/iPhone Simulator/User/Applications/5B888456-40FF-4C72-A2ED-5D5CFA287777/MyApp.app/test.xml

This image never loads (nor does any image): /Users/me/Library/Application Support/iPhone Simulator/User/Applications/5B888456-40FF-4C72-A2ED-5D5CFA287777/MyApp.app/background.png

+1  A: 

You can use [UIImage imageNamed:@"background.png"].

This will load background.png (which should be located in your Resources folder in Xcode).

pgb
I'm trying to compose a string to send to another method that loads the image. It takes a string, then usesNSURL *url = [NSURL URLWithString:imgPath];to compose an NSURLConnection to retrieve the image. I know that sounds convoluted, but the image I'm trying to load may or may not be in the mainBundle. If the image is on a remote server, it loads fine by sending the correct URL, but I can't get it to load from the main bundle. If the image IS in the mainBundle, what string do I pass to the method?
Why not check imageNamed first and if it fails, construct your URL?
Roger Nolan