呈现内容后的UIWebView序列化 [英] UIWebView serialization after content has been rendered

查看:107
本文介绍了呈现内容后的UIWebView序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的HTML文档,我需要在我的应用程序中显示。它使用CSS Columns,并水平滚动。我尝试做的是归档UIWebView,它将文档呈现为当前状态,这样我就可以从CoreData中取消归档,并且不必让用户等待几秒钟直到它被渲染。所以在我的UIWebViewDelegate中,我在调用webViewDidFinishLoad时使用以下方法进行序列化(内容是从字符串加载的,而不是从外部源加载的):

I have a very large HTML Document that I need to show in my app. It utilizes CSS Columns, and scrolls horizontally. What I try to do is archive the UIWebView that renders the document in its current state, so that I can unarchive it from CoreData and don't have to let the user wait for a few seconds until it's rendered. So inside my UIWebViewDelegate, I serialize using the following method when webViewDidFinishLoad is called (the content is loaded from string, not from external sources):

[NSKeyedArchiver archivedDataWithRootObject:self.webView];

我检查了多次调用webViewDidFinishLoad,但事实并非如此。这和核心数据保存实际上是有效的,即它确实在下次启动应用程序时正确保存和加载。然而,虽然它保存了UIWebView本身,但似乎内容没有加载到它中,这使得整个过程对我来说有点无用。我对以某种方式保存对象的理解是错误的,还是只是一个实现问题?

I checked if webViewDidFinishLoad is called multiple times, but it isn't. This and the core data saving actually works, i.e. it does save and load properly the next time the app is launched. However, while it saves the UIWebView itself, it seems like the content isn't loaded into it, which makes the whole procedure kinda useless for my purpose. Is my understanding of saving an object this way wrong, or is it simply a question of implementation?

非常感谢!

推荐答案

我认为你不应该归档UIWebview。相反,您可以使用自定义CSS元素将html文档文件保存在应用程序的文档目录中,并使用以下代码使用文件路径进行渲染。

I dont think you should be archiving the UIWebview. Instead you can save the html document fil with custom CSS elements in the documents directory of the app and render it using the filepath using the following code.

self.webview.scalesPageToFit=  YES;                        
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];

这篇关于呈现内容后的UIWebView序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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