Requirements: text and text mix the content of the article, at the end of the article there are recommended related articles, related videos, and comments section
Implementation: a cell in a section of tableView holds a wkWebView,wkWebView loads an HTML string, or h5(currently used to load H5).
Problem: need to get the page height after loading h5 page, refresh tableVie, but: //didFinishNavigation call does not mean that all contents of the web page have been loaded. For example, some JS files may not have been loaded. The solution was to wait about 30ms after completion of didFinishNavigation, // or notify the completion of LOADING of JS scripts in native web pages through JS integration.
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
WS()
[webView evaluateJavaScript:@"document.body.scrollHeight;" completionHandler:^(id result, NSError * error) {
if (result) {
CGFloat webViewHeight = [result floatValue];
if (webViewHeight>0) {
weakSelf.model.webHeight = webViewHeight+20;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
[weakSelf.mainTableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:(UITableViewRowAnimationAutomatic)];
}
}
}
Copy the code
However, the above callback method, callback can not get the height, so I delay 1 second to get, or not necessarily get.
Solution: H5 side in the declaration cycle after the page height of the js interaction to me, I then update the page ππποΏ½