tableview嵌套webview 只更新高度

webveiw 加载内容的时候 他的didfinish方法会走几次 这个时候动态获取加载内容的实际高度,然后只需更新高度 内容不需要更新了,尤其是webview在tableView中使用的时候。
在vc 创建webview

    _webview = [[UIWebView alloc]init];
     _webview = [[UIWebView alloc]initWithFrame:CGRectZero];
     _webview.delegate = self;
     _webview.backgroundColor = [UIColor clearColor];
     _webview.opaque = NO;//滑动的黑色条
    //    _webInfo.scalesPageToFit = YES;
     _webview.userInteractionEnabled = NO;

cell 中添加webview

 static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        [cell.contentView addSubview:_webview];
        /* 忽略点击效果 */
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    return cell;

web代理:只更新高度 不要更新内容 因为该方法会执行多次

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
//获取到webview的高度
CGFloat height = [[_webview stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
_webview.frame = CGRectMake(16 ,6, SCREEN_WIDTH - 16*2, height);
[_tableView beginUpdates];
[_tableView endUpdates];
}

你可能感兴趣的:(tableview嵌套webview 只更新高度)