Ios web interaction indexing: highly available, and iosweb Indexing

Source: Internet
Author: User

Ios web interaction indexing: highly available, and iosweb Indexing
Ios web interaction indexing: highly available. For how to obtain the height of WebView content, I believe many people have stepped on and cannot obtain the accuracy height, leading to page layout errors, I found a lot of information, but I cannot solve the problem. The following is my personal experience: project requirement implementation.H5 articles & Native commentsEffect: The article loads the H5 link, and the comment information is provided by the background interface, which is displayed as a list. Implementation ideas:

1. Load the H5 link of webView and set it to the headerView of tableView. The comment below is loaded and displayed with Cell.

2. In the webView callback method webViewDidFinishLoad, retrieve the webpage content height, set it to the webView height, and assign the webView to the tableView headerView again.

Tip: when assigning a View to the tableHeaderView of UITableView, you do not need to manually set the height,HeaderViewThe height of the View is automatically used.

As shown in the preceding figure, there are many similar methods. The final results are hard to obtain accurate heights, whether obtained by JS or contentSize, rather than the method:

When the webViewDidFinishLoad proxy method is called, the page may not be fully displayed, and some images may not be loaded yet. As a result, the obtained height is not the final height. After the image is loaded, the browser re-typeset, and we gave an error height before this, leading to an exception in display.

The cause of the problem has been determined. solution:

After webViewDidFinishLoad, How can I obtain the webpage content height change?


Specific implementation process:

Add a listener to the contentSize attribute of the scrollView of webView. The contentSize will change whenever the content changes. capture this change and implement it in the monitoring method.WebViewDidFinishLoadThe code in, that is, to obtain the latest content and assign it to webView:

In addition, the solution to obtaining high accuracy using webView in cell is the same as above, but it only needs to be noted that using webView in cell involves cell reuse, which may cause webView to be loaded multiple times during sliding list, the cache height is recommended because it affects performance.


If you do not want to listen, you must first doubt yourself, do not doubt me!

1. Make sure that the webview has been added to the page and can be properly displayed. Then, continue to get the content height. If none of them are displayed, don't come to me!

2. Add a listener to the scrollview of webview. Do not add the listener to webview. Otherwise, you will not use the listener method when you are exhausted!

3. If you are using swift, learn the relevant materials first.


Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.