2013-05-27 47 views
1

內容我已經給網頁視圖在分區域的UITableViewCell這樣UIWebView的大小不是設置在網頁視圖

if(section==0) 
    { 
     static NSString *[email protected]"Cell"; 
     UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if(cell == nil) 
     { 
      cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease]; 


      webView = [[UIWebView alloc] initWithFrame:CGRectZero]; 
      webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 
      webView.tag = 1001; 
      webView.userInteractionEnabled = NO; 
      webView.backgroundColor = [UIColor clearColor]; 
      webView.opaque = NO; 


      [cell addSubview:webView]; 
     } 


    webView = (UIWebView*)[cell viewWithTag:1001]; 

     webView.delegate=self; 
     webView.frame=CGRectMake(0, 0, 300, 1000); 
     NSLog(@"current mode: %@", [[NSRunLoop currentRunLoop] currentMode]); 
     [webView loadHTMLString: [NSString stringWithFormat:[arrSecCount objectAtIndex:0], indexPath.section]baseURL:nil]; 
     return cell; 

    } 

where as the content in webview is dynamic.in 

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

    { 
    if(indexPath.section==0) 
    { 
     NSString *output = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"]; 

    return [output floatValue]+300; 

     } 
     } 

但是當視圖內容增加了它在其它部分沒有裝修overiding height.i已經嘗試了很多方法搜索但沒用。 幫我看看你的建議

+0

當您嘗試這樣做時發生了什麼? – Balu

+0

wats錯了嗎? – user2197875

+0

你在輸出對象中得到了正確的值嗎? – Balu

回答

0

我想的UITableViewCell會得到其高度甚至裝載的WebView內容之前...

什麼建議是,在web視圖的委託方法:

- (void)webViewDidFinishLoad:(UIWebView *)webView 

你做一個

[tableView reloadData]; 

這意味着你必須保持到web視圖的參考,而不是以往任何時候都重裝HTMLString ytime單元格內容已更新...

+0

無需在indexpath的heightforrow中給出任何東西? – user2197875

+0

是的,我的回答假設您的webview完成加載之前調用方法heightForRowAtIndexPath。這意味着,web視圖將不會顯示任何內容,並且高度不正確。 – delannoyk

+0

它不工作單元格不顯示 – user2197875