如何在Swift 4中的WebView中显示大量数据 [英] How to display heavy data in webview in swift 4

查看:70
本文介绍了如何在Swift 4中的WebView中显示大量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个应用程序中,我必须在来自Web服务响应的Web视图中显示html内容.如果html数据较小,则它将显示在webview中.但是,当html内容非常繁重时,在Web视图应用中显示的那段时间就会消失.

In one of my applications, I have to show html content in a web view which comes from web service response. If the html data is smaller then it will display in webview. But when html content is very heavy that time at the time of display in web view app kills.

我只是检查了一件事情,我创建了一个HTML文件,其中包含大量数据并保存在项目中.我已在webview中成功显示此文件.那为什么webview不能显示大量的html数据.

One thing I did just only to check, I create one html file which contains heavy data and saved in project. I display this file in webview successfully. Then why webview not show heavy html data.

我使用此方法将html字符串显示到webview中.

I used this method to show html string into the webview.

webView.loadHTMLString(htmlString , baseURL: nil)

推荐答案

我遇到了这类问题.我在这个问题上搜索了很多.出现此问题是因为内存不足.经过大量搜索和调试后,我得到了此问题的实际原因.

i had this type of issue. I searched a lot on this issue. This issue raised because memory. After searching a lot and debugging , i got the actual reason of this issue.

当HTML内容太大时,当我们试图将此html内容加载到uiwebview中,并且同时将uiwebview高度wrt增加到uiwebview的内容大小时,就会出现时间内存问题.

When Html content too large and when we are trying to load this html content into uiwebview and also increasing uiwebview height wrt to content size of uiwebview, that time memory issue raised.

第一个解决方案:如果您具有静态html内容,则可以将其存储在项目中的一个.html扩展文件中,并将此文件显示到uiwebview中.这样您就不会提出任何问题,并且uiwebview的高度也会增加uiwebview的内容大小.

First Solution : If you have static html content then you can store this in one .html extension file within project and display this file into uiwebview. This way you can't raised any issue and uiwebview height also increases wrt to content size of uiwebview.

第二个解决方案:如果您的uiwebview高度急剧增加,则可以在某种情况下将uiwebview的高度设置为一件事.哪个可以解决您的问题.

Second Solution: If your uiwebview height increases drastically then do one thing set height of uiwebview in that case at certain level. Which resolve your problem.

这篇关于如何在Swift 4中的WebView中显示大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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