iPhone-如何在UIWebView中预加载本地文件? [英] iPhone - How to preload a local file in a UIWebView?

查看:62
本文介绍了iPhone-如何在UIWebView中预加载本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为UIWebView预先加载带有嵌入式图像的本地文件的内容?

Is it possible to preload content of a local file with embedded images for a UIWebView?

这是我如何在UIWebView中加载数据:

This is how I'm loading the data inside the UIWebView:

NSString *urlString = [[NSBundle mainBundle] pathForResource:@"info" ofType:@"html"];
NSString *htmlContent = [NSString stringWithContentsOfFile:urlString encoding:NSUTF8StringEncoding error:nil];
[myWebView loadHTMLString:htmlContent baseURL:nil];

但是UIWebView仍然需要一些时间来显示内容.有什么方法可以在应用启动时将这些内容放入浏览器缓存中吗?

But the UIWebView still needs some time to display the content. Is there any way to put this content into the browser cache on app start?

推荐答案

如果您在应用启动时创建浏览器对象并立即加载HTML字符串,则它应该可以正常工作,以便以后显示视图.

If you create the browser object on app start and load the HTML string immediately, it should work fine to display the view later.

另一种选择是在必要时分配它,但是直到完成加载后才真正显示视图(等待-(void)webViewDidFinishLoad:(UIWebView *)webView 在网络上调用视图的代表,然后再显示它.

Another option would be to allocate it when necessary, but not actually show the view until it's done loading (wait for - (void)webViewDidFinishLoad:(UIWebView *)webView to be called on the web view's delegate before showing it).

另外,打电话更有意义

[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:urlString]]];

比使用 loadHTMLString:方法好吗?这样,您不必自己将HTML字符串加载到内存中,并且Web视图可以直接从磁盘加载它.

than using the loadHTMLString: method? That way, you don't have to load the HTML string into memory yourself and the web view can load it directly from disk.

这篇关于iPhone-如何在UIWebView中预加载本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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