先添加UIWebView的委托
webViewShow = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)]; //不能设为Zero,会报错
webViewShow.scrollView.scrollEnabled = NO;
NSURL *url = [NSURL URLWithString:@"http://changba.com/s/yLBubzGZEWG2g5F_ujOXZg?code=Gt1bjDM0qnHE46WKYVhlhDLs9x56uVGw3FYt_NMSxjPuh9H1aWo-b-iI1MpnQdDG4IHTGUUNB0_HfcWJHso5ctOASF3E2S-10Xv0Gm3gsZk"];
[webViewShow setScalesPageToFit:YES];
webViewShow.delegate = self;
webViewShow.scrollView.delegate = self;
webViewShow.autoresizesSubviews = YES;
[webViewShow sizeThatFits:CGSizeMake(self.view.frame.size.width, 100)];
NSURLRequest *request=[[NSURLRequest alloc] initWithURL:url];
[webViewShow loadRequest:request];
self.egoTableView.tableHeaderView = webViewShow;//先加入TablView的头或尾
//接着在委托重设高度
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//根据JS得到内容的高度 @"document.height" 或者 @"document.documentElement.scrollHeight" 或者 @"document.body.offsetHeight"具体找网 页人员确认
float newSize = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] floatValue];
NSLog(@"Resizing webview from %.2f to %.2f", webView.frame.size.height, newSize);
webView.frame = CGRectMake(webView.frame.origin.x, webView.frame.origin.y, webView.frame.size.width, newSize);
[self.egoTableView setTableHeaderView:webViewShow]; //重设TableHeaderView
}