views:

105

answers:

1

I'm working with a UIWebView loading local (i.e. in the source bundle) html pages, ala Apple's Transweb example. Loading the first page is trivial. However, I have added a second html page and linked to it from the first. Attempting to link to a second page doesn't seem to work.

Anyone know how to make this work?

Thanks.

A: 

I had trouble accessing relative resources when loading a file by path. Try loading the file into memory, either as a string or data, so that you can explicitly pass in a base URL.

NSURL *bundleURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]];

then

[yourWebView loadHTMLString:yourHTML baseURL:bundleURL];

or

[yourWebView loadData:yourHTML MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:bundleURL];

I used this for accessing image resources, but it may also help with relative links.

drawnonward
Maybe I'm misunderstanding you. The code you've written above is how I load a page into a webview (i.e. "one.html"). That much is already clear to me. But when I then click on a link in one.html that leads to two.html, I want that to work properly. Loading all the possible destinations for the links in one.html just in case one of the links gets clicked seems clumsy. But perhaps that's not what you're saying.
mwt
At some point when I was trying to solve this problem, I found that letting the UIWebView pick the base url by calling `loadRequest:` with a file url did not work, so I was suggesting you avoid that call. If you are not using `loadRequest:` then maybe you can log the request in `webView:shouldStartLoadWithRequest:navigationType:` and see what is being loaded when you click a link.
drawnonward