IOS TableViewCell nested WebView

IOS TableViewCell nested WebView
IMG_0521.JPG

new project, met a new demand: tableview in a cell nested web view, want to let Web view according to the content of the adaptive height, cell according to webView adaptive height.
for this demand, we need only 2 steps to complete.

1 how to get the height of WebView

WebView height, I found the answer from http://stackoverflow.com/questions/7341767/ios-resize-uiwebview-to-fit-content
http://www.xuebuyuan.com/2035051.html.

Get to the height of the WebView / / CGFloat height = [[self.webView stringByEvaluatingJavaScriptFromString:@ floatValue] "document.body.offsetHeight"];

2 get to the height of WebView, re reloadTableview can

- (void) viewDidLoad viewDidLoad] _webView {[super; [[UIWebView = alloc]initWithFrame:CGRectMake (0, 0, kScreenWidth, 1); _webView.delegate = self; _webView.scrollView.scrollEnabled = NO; / / url [self.webView loadRequest:[[NSURLRequest alloc] pre loaded initWithURL:[NSURL URLWithString:@ https://www.baidu.com/ (void) -]]];} didReceiveMemoryWarning {[super didReceiveMemoryWarning]; of any resources that can / / Dispose be recreated. mark - TableViewDelegate & #pragma}; TableViewDatasource - (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section the number of {/ / Return rows in the section. return 3;} - (UITableViewCell *) tableView: (* UITableView) tableView CE LlForRowAtIndexPath: (NSIndexPath * indexPath) {if (indexPath.row = = 1) {static NSString = *identifier @ *cell = "cell"; UITableViewCell [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell! = [[UITableViewCell) {cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; [cell.contentView addSubview:_webView]; / * * / [cell setSelectionStyle:UITableViewCellSelectionStyleNone] click ignore the effect of return cell}else{static;}; NSString * identifier = @ "cell UITableViewCell *cell = [tableView; dequeueReusableCellWithIdentifier:identifier]; if (! Cell) {cell = [[UITableViewCell alloc ]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; cell.textLabel.text [NSString stringWithFormat:@} = "index====%ld", (long) indexPath.row]; return cell;}} - (CGFloat) tableView: (UITableView * tableView) heightForRowAtIndexPath: (NSIndexPath *) indexPath; if (indexPath.row = = 1) {{/ * access to content highly by the WebView agent, the content of height is set to cell high return _webView.frame.size.height}else{* /; return 100;}} - (void) tableView: (UITableView * tableView) didSelectRowAtIndexPath: (NSIndexPath * indexPath) {[tableView deselectRowAtIndexPath:indexPath animated:YES]; #pragma mark Delegate Methods} - UIWebView - (void) webViewDidFinishLoad: (UIWebVie W * webView) {/ / get to the WebView CGFloat height [[self.webView stringByEvaluatingJavaScriptFromString:@ height = "document.body.offsetHeight" floatValue]; self.webView.frame = CGRectMake (self.webView.frame.origin.x, self.webView.frame.origin.y, kScreenWidth, height); [self.tableView reloadData];} - (void) webViewDidStartLoad: (UIWebView * webView) {NSLog (@ webViewDidStartLoad);} - (void) webView: (UIWebView * webView) didFailLoadWithError: (nullable * NSError) error {NSLog (@ "didFailLoadWithError===%@", error);}
IOS TableViewCell nested WebView
renderings

PS

Demo address, please click here.