views:

199

answers:

2

Hi,

In My Iphone app I display a local HTML file into a UIWebView. Inside the html code I try to display a local picture who is store in the repertory 'Ressource'. I want to know what is the path, I can't point to my picture.

Thanks,

+1  A: 

Assuming your image is named MyImage.png and is in your app bundle's Resources folder:

NSString *imagePath = [[NSBundle mainBundle] pathForResource: @"MyImage" ofType: @"png"];
Costique
no thats not what I want, I have an HTML file, inside this code I display an image like <img src="path"> I want to know the the path (my image is in the bundle Ressource folder
ludo
The code above gives you the path to the image file, which you can insert into the HTML string. Do you mean you need to parse HTML to get the value of src attribute instead?
Costique
I can use your code and paste it inside my html? it will work? I never try that so strange, I will try it tomorrow and get back to you.
ludo
No, that line of code is in Obj-C and won't work in HTML. With it you get an NSString which holds the full path to the image. You need to insert the string's value (the path) into your HTML string. One approach is to replace src="path" with src="%@" and then [NSString stringWithFormat: myHTMLString, imagePath] will return the HTML string with the image path inserted in place of %@. Obviously, you need to read your HTML file into myHTMLString first.
Costique
A: 

Hello Iudo,

there is no need to put the path into the html-page for each image manually.

Simply reference the images without a path, e.g. and store the html-file and the images in the resource folder. Then use the following code to set the content of the UIWebView:

NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"help-en" ofType:@"html"];
NSMutableString *html    = [[NSMutableString alloc] initWithContentsOfFile: filePathString]; 
NSURL *aURL = [NSURL fileURLWithPath:filePathString];
[webView loadHTMLString:html baseURL:aURL];
Stiefel