UIWebView通过更有效的方式缩短了加载时间 [英] UIWebView lower loading time with a more efficient way

查看:53
本文介绍了UIWebView通过更有效的方式缩短了加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在下载多个html,并将它们作为字符串保存在本地的 NSArray 中。
然后,我使用3个 UIWebViews 加载内容。用户总是使用以下命令在后台加载一个 UIWebView 和另外两个 UIWebView

I'm downloading multiply htmls and save them locally as strings in an NSArray. Then I'm using 3 UIWebViews to load the content. The user always sees one UIWebView and 2 more UIWebViews are loaded in the background using:

[_firstWebView loadHTMLString:nextHtml.body baseURL:nil];

当用户在 UIWebViews 之间移动时,我如果一次移动2个 UIWebViews ,仍然可以看到1-2秒的缓慢加载时间。我曾考虑过将5个或什至7个 UIWebViews ,但恐怕会严重影响内存使用。

When the user moves around between UIWebViews I can still see slow loading times of 1-2 seconds if he moves 2 UIWebViews at a time. I thought about going to 5 or even 7 UIWebViews but I'm afraid it will impact the memory usage heavily.

另一个以为我将内容本地保存为 NSData ,然后用

Another thought I had was saving the content locally as NSData and then load it with

[web loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]]; 

但是我不确定这会为我带来任何改善吗?

But I'm not sure that will gain me any improvement or will it?

另一个想法是我的应用程序(屏幕上的动画)上的内容正在减慢加载时间,因此也许我应该 loadHTMLString:nextHtml

Another thought was that something in my app (animation on the screen) is slowing down the loading time so maybe I should loadHTMLString:nextHtml on a different thread?

谢谢

推荐答案

最近我做了一些有关在后台将内容加载到UIWebView的研究。我发现即使成功的loadRequest也不起作用,而Webview是不可见的,并且未在某处添加为子视图。

Recently I did some research about loading content to UIWebView in the background. I've found that even successful loadRequest has no effect while webview is invisible and not added as subview somewhere.

但是,如果我在加载之前对视图进行了某些访问,它将开始

But if I make some access to view before loading, it starts to show content loaded in the background.

所以我先隐藏视图,然后在其中加载内容,然后再向用户展示之前使该视图再次可见:

So I hide the view first, then load content in it and before showing it to user make the view visible again:

在加载方法中:

// make some access to view to reflect content changes
self.webView.hidden = YES;

[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:someurl]]];

当用户切换到Web视图时:

When user switches to the webview:

// make view visible again
self.webView.hidden = NO;

这种方法对我有用。希望它也能为您指明正确的方向。

This approach worked for me. Hope it also point you in right direction.

这篇关于UIWebView通过更有效的方式缩短了加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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