iPhone - How to preload a local file in a UIWebView?

℡╲_俬逩灬. 提交于 2019-12-11 07:36:43

问题


Is it possible to preload content of a local file with embedded images for a 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];

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?


回答1:


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

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).

Also, would it make more sense to call

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

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.



来源:https://stackoverflow.com/questions/3307767/iphone-how-to-preload-a-local-file-in-a-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!