After browsing quite a bit, I still can't figure this out. I've added a HTML page and its images directory into my project Resources group in Xcode (Copied them over).
When I try to load the webview with the following code, the text is displayed fine, but the images aren't loaded.
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];
Any help is much appreciated!
EDIT: Sorry about the delay, here's 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 it was an issue with the path. Apparently <img src = "images/bg.png">
doesn't work, but if I copy bg.png to the root directory and say <img src = "bg.png">
everything works fine. I'm still not sure where I'm going wrong with this.
Thanks,
Teja.