After watching a bit, I still can not figure it out. I added an HTML page and its image directory to my project resource group in Xcode (copied them).
When I try to load the WebView using the following code, the text appears in order, but the images do not load.
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"index.html"]; NSString *htmlContent = [NSString stringWithContentsOfFile:path]; NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; [[tempWebView mainFrame] loadHTMLString:htmlContent baseURL:url];
EDIT: Sorry for the delay, here are some basic html that failed.
<html> <body> <img src="images/bg.png"></img> </body> </html>
And my edited code looks like this:
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]; NSURL *url = [NSURL fileURLWithPath:path]; [[webView1 mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
EDIT2: Just realized this is a problem with this path. Apparently, <img src = "images/bg.png"> does not work, but if I copy bg.png to the root directory and say <img src = "bg.png"> everything will be fine. I'm still not sure where I am going wrong.
cocoa webview
Tejaswi yerukalapudi
source share