远程图像不会显示在UIWebView中显示的html页面中 [英] Remote image doesn't get displayed in html page displayed in UIWebView

查看:88
本文介绍了远程图像不会显示在UIWebView中显示的html页面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码

<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&#39;ve Got a Friend In Me" src="http://ax.phobos.apple.com.edgesuite.net/images/
badgeitunes61x15dark.gif"></img>
</a>

来自apple的文档

http:// developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/iTunesLinks.html#//apple_ref/doc/uid/TP40007896-SW1

当包含该href的html页面被加载到浏览器中时,将显示图像,但是当它加载到UIWebView中时,它不会显示。

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:未调用以下网址

ShouldStartLoadWithRequest: does not get called for the following URL

http://ax.phobos.apple.com.edgesuite.net/images/
badgeitunes61x15dark.gif

为什么不调用它,为什么它在浏览器中工作但在UIWebView中不工作?

Why does it not get called and why does this work in a browser but not in UIWebView?

推荐答案

嗯,我刚用你的HTML构建了一个原型,它对我来说很好。

Well, I just built a prototype with your HTML, and it worked fine for me.

然而,一些想法:


  • 首先,如果你在您的Web视图委托中实现 webView:shouldStartLoadWithRequest:navigationType:,不要期望对HTML页面中的每个项目进行回调。如果我没记错的话,它只会调用顶级请求(例如整个页面)。所以,我不希望只为那个 img 资源获得回调。

  • 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 one img resource.

因为我们已经确定实现 webView:shouldStartLoadWithRequest:navigationType:将无法执行您想要的操作,您可能希望完全删除它。当我第一次懒洋洋地把它放在我的代码中时,我忘了从那个方法返回YES; 。由于Objective-C是一种相当松散的语言,应用程序已构建并运行,但显然将 NO 作为该方法的隐式返回值。 停止加载请求。如果图像是您拥有的样本页面中的唯一内容,则您不会看到任何内容(并且可能错误地认为这仅仅是因为img本身)。

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 to return YES; from that method. Since Objective-C is a rather loose language, the app built and ran, but obviously took NO to be the implicit return value from that method. NO stops 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).

我不知道这是否仅存在于您在问题中发布的HTML中,或者它是否也在真实代码中。但是,在images /之后,您的 img src URL中有空格。这显然会让这个休息。

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 src URL, after "images/". That would obviously make this break.

在我的测试中,我也开始使用一个不能缩放内容的网页。该图片相当小,因此如果您不缩放网页视图以适应并在iPhone / iPod上查看,您可能没有注意到这么小的图像。

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;

无论如何,这就是我所能想到的。就像我说的,它对我有用。这不是图像本身,也不是Mobile Safari与 UIWebView 之间的任何区别。

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.

仔细检查并报告:)

这篇关于远程图像不会显示在UIWebView中显示的html页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆