webveiw 加載內(nèi)容的時(shí)候 他的didfinish方法會(huì)走幾次 這個(gè)時(shí)候動(dòng)態(tài)獲取加載內(nèi)容的實(shí)際高度畏妖,然后只需更新高度 內(nèi)容不需要更新了棘利,尤其是webview在tableView中使用的時(shí)候势篡。
在vc 創(chuàng)建webview
_webview = [[UIWebView alloc]init];
_webview = [[UIWebView alloc]initWithFrame:CGRectZero];
_webview.delegate = self;
_webview.backgroundColor = [UIColor clearColor];
_webview.opaque = NO;//滑動(dòng)的黑色條
// _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];
/* 忽略點(diǎn)擊效果 */
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return cell;
web代理:只更新高度 不要更新內(nèi)容 因?yàn)樵摲椒〞?huì)執(zhí)行多次
-(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];
}