iPhone SDK:UIWebView用于停止加载/下载图像 [英] iPhone SDK: UIWebView to stop images from loading/downloading

查看:108
本文介绍了iPhone SDK:UIWebView用于停止加载/下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Xcode中使用UIWebView,以便在加载页面时不下载图像(以便加快页面加载速度)?

How can I use the UIWebView in Xcode so that when it loads up pages it DOESN'T download the images (to cause a faster loading page)?

推荐答案

UIWebView 是WebKit的完整 WebView 的苍白,可怜的小阴影,为此这很简单。 -webView:shouldStartLoadWithRequest:navigationType:仅调用导航。它不会像Mac上的 WebPolicyDelegate 这样的每个请求调用。使用 UIWebView ,以下是我将如何解决此问题:

UIWebView is a pale, poor little shadow of WebKit's full WebView, for which this is easy. -webView:shouldStartLoadWithRequest:navigationType: only gets called for navigation. It doesn't get called for every request like WebPolicyDelegate does on mac. With UIWebView, here's how I would attack this problem:

实现 -webView:shouldStartLoadWithRequest :navigationType:并将其设置为始终返回。但是你也会接受请求并产生一个 NSURLConnection 。当 NSURLConnection 完成获取数据时,您将查看任何IMG标记并将其修改为您想要的任何占位符。然后,您将使用 -loadHTMLString:baseURL:将结果字符串加载到 UIWebView 中。

Implement -webView:shouldStartLoadWithRequest:navigationType: and set it to always return NO. But you'll also take the request and spawn an NSURLConnection. When the NSURLConnection finishes fetching the data, you're going to look through it for any IMG tags and modify them to whatever placeholder you want. Then you will load the resulting string into the UIWebView using -loadHTMLString:baseURL:.

当然,在iPhone上解析HTML并不是一项微不足道的任务,Javascript加载器会给你带来麻烦,所以这不是一个完美的答案,但它是我所知道的最好的。

Of course parsing the HTML is not a trivial task on iPhone, and Javascript loaders are going to give you trouble, so this isn't a perfect answer, but it's the best I know of.

这篇关于iPhone SDK:UIWebView用于停止加载/下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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