WKWebview 拼接tableview,获取web内容高度

时间:2023-03-10 05:49:15
WKWebview 拼接tableview,获取web内容高度
- (void)addWKWebView
{
_webView = [[WKWebView alloc] initWithFrame:CGRectMake(, , SCREEN_WIDTH, 0.1)];
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_activityModel.shareLink]]];
_webView.scrollView.scrollEnabled = NO;
_webView.UIDelegate = self;
_webView.navigationDelegate = self;
[_tableView setTableHeaderView:_webView];
[SVProgressHUD show];
} - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
[webView evaluateJavaScript:@"document.getElementById(\"content\").offsetHeight"
completionHandler:^(id _Nullable result,NSError * _Nullable error) {
// 获取页面高度,并重置webview的frame
_webViewHeight = [result doubleValue];
CGRect frame = webView.frame;
frame.size.height = _webViewHeight;
webView.frame = frame;
[_tableView beginUpdates];
[_tableView setTableHeaderView:_webView];
[_tableView endUpdates];
[self getActivityComments];
}];
} - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation{ } - (void)addTableView
{
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(,, SCREEN_WIDTH, SCREEN_HEIGHT-- ) style:UITableViewStylePlain]; [_tableView setBackgroundColor:[UIColor clearColor]];
[_tableView setDelegate:self];
[_tableView setDataSource:self];
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_tableView.separatorColor = SEPARATOR_COLOR_SYSTEM;
[self.view addSubview:_tableView];
[self loadLoadMoreFooter:_tableView action:@selector(loadMoreData)]; }