0

I'm parsing an RSS feed (which comes in as an XML) and loading it into a UIWebView - and that works perfectly well. The problem is with the occasional <img> tags that are in the XML - the images they call aren't showing up (although I do get a placeholder bounding-box where they should be appearing.)

The issue is that those <img> tags unfortunately contain only partial paths, with no domain name - for example:

<img src="/news-media/images/football/6.jpg" />

To fix that I tried specifying the default domain name in the baseURL argument:

NSURL *baseURL = [NSURL fileURLWithPath:@"http://www.myDomain.com"];
[theWebView loadHTMLString:tempHtmlString baseURL:baseURL];

This does not work - the HTML is still loading fine, but the images are not showing up. This does however eliminate the "broken image" icons I was getting before on the images (the kind you usually get when a web-page is trying to load an image that's missing.) Also, I sometimes get a "received memory warning" message - but not always. Seems to happen when loading a page that contains multiple photos. But even when a page has only one photo and I do not receive the "memory" warning, the photo itself doesn't get loaded.

Any ideas what to do? Am I gonna have to manually append the base-URL to all occurrences of the <img> tag?

4

1 回答 1

1

您正在将基本 URL 创建为文件 URL(即设备上本地文件的 URL)。您希望 URL 引用远程服务器。尝试这个:

NSURL *baseURL = [NSURL URLWithString:@"http://www.myDomain.com"];
[theWebView loadHTMLString:tempHtmlString baseURL:baseURL];
于 2013-07-24T01:40:45.207 回答