我有一个TableView,在第一个单元格中,我在WebView中显示HTML内容。
我希望此单元格具有WebView中内容的高度。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if(indexPath.row == 0) {
let cell = articleTableView.dequeueReusableCellWithIdentifier("articleContentCell", forIndexPath: indexPath) as! ArticleContentTableViewCell
cell.articleContentWebView.loadHTMLString(newsItem.entry.content, baseURL: nil)
return cell
}
...
}
我如何计算?我是否可以在CellForRowAtIndexPath中计算它,因为单元格尚未渲染?我可以在webview中获得scrollView高度,但它并没有让我达到高度。
答案 0 :(得分:0)
- (void) loadString (NSString *)Str{
[theWebView loadHTMLString:Str baseURL:nil];}
#pragma mark - UIWebView Delegate methods
- (void)webViewDidFinishLoad:(UIWebView *)webView {
if ([self.delegate respondsToSelector
:@selector(updateCellHeight:currentSection:)]) {
CGRect frame = webView.frame;
frame.size = [webView sizeThatFits:CGSizeZero];
frame.size.height += 10.0f;
webView.frame = frame;
webView.delegate = nil;
[self.delegate updateCellHeight:webView.scrollView.contentSize.height currentSection:webView.tag];
}
}
#pragma mark - RichTextCellDelegate
- (void) updateCellHeight:(CGFloat)richTextHeight currentSection:(NSInteger)Section
{
if (![sectionArray containsObject:[NSNumber numberWithInteger:Section]]){
[sectionArray addObject:[NSNumber numberWithInteger:Section]];
NSLog(@"CurrentHeight%f",richTextHeight);
richTextCellHeight = richTextHeight;
savedIndexPath = Section;
//[theTableView reloadData]; // No Need to load Whole Table
NSIndexSet *indexes = [[NSIndexSet alloc] initWithIndex:Section];
[theTableView reloadSections:indexes withRowAnimation:UITableViewRowAnimationNone];
}
}