问题
The following code
<a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=156093464&id=156093462&s=143441">
<img height="15" width="61" alt="Randy Newman - Toy Story
- You've Got a Friend In Me" src="http://ax.phobos.apple.com.edgesuite.net/images/
badgeitunes61x15dark.gif"></img>
</a>
Is from apple's documentation
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/iTunesLinks.html#//apple_ref/doc/uid/TP40007896-SW1
When a html page containing that href is loaded into a browser the image is displayed, however when its loaded into a UIWebView it isn't displayed.
ShouldStartLoadWithRequest: does not get called for the following URL
http://ax.phobos.apple.com.edgesuite.net/images/
badgeitunes61x15dark.gif
Why does it not get called and why does this work in a browser but not in UIWebView?
回答1:
Well, I just built a prototype with your HTML, and it worked fine for me.
However, a few thoughts:
First, if you implement
webView:shouldStartLoadWithRequest:navigationType:in your web view delegate, don't expect a callback for every single item in your HTML page. If I remember correctly, it only calls that for top level requests (e.g. the whole page). So, I would not expect to get a callback just for that oneimgresource.Since we already established that implementing
webView:shouldStartLoadWithRequest:navigationType:won't do what you want, you might want to remove it altogether. When I first lazily put it in my code, I forgot toreturn YES;from that method. Since Objective-C is a rather loose language, the app built and ran, but obviously tookNOto be the implicit return value from that method.NOstops the request from loading. If the image was the only thing in a sample page you had, you wouldn't see anything (and maybe falsely think it was just because of the img itself).I can't tell if this is only in the HTML that you posted in your question, or if it's in the real code, too. But, you have whitespace inside your
img srcURL, after"images/". That would obviously make this break.In my test, I also started with a web page that didn't scale content to fit. That image is rather small, so if you don't scale your web view to fit, and view it on an iPhone/iPod, you might not have noticed such a small image.
webview.scalesPageToFit = YES;
Anyway, that's all I can think of. Like I said, it works for me. It's not the image itself, or any difference between Mobile Safari, vs. UIWebView.
Double check and report back :)
来源:https://stackoverflow.com/questions/11659324/remote-image-doesnt-get-displayed-in-html-page-displayed-in-uiwebview