我有一个UITableView
单元,它的大小取决于它的内容(可能有几行文本)。
由于在布局单元格之前调用了heightForRowAtIndexPath
,所以我只是通过在文本字符串上调用[NSString sizeWithFont]
来猜测正确的高度。有更好的方法来设置高度后,我已经在单元格中的文本,并有一个确切的大小应该是什么?
我的问题是,每个单元格都包含一个具有不同(静态加载)内容的UIWebView
,我无法根据内容计算出适当的高度。有办法这样做吗?我试过这样的方法:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
WebViewCell *cell = (WebViewCell*)[self tableView:tableView cellForRowAtIndexPath:indexPath];
[cell setNeedsLayout];
[cell layoutIfNeeded];
return cell.bounds.size.height;
}
单元本身是从一个nib加载的,它只是一个包含一个UITableViewCell
的UIWebView
。(如果单元格只是调整到最大的html内容,虽然可变的高度会更好,也会很好)。
发布于 2016-10-07 21:17:01
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath {
UITableViewCell *cell = [self tableView: tableView cellForRowAtIndexPath: indexPath];
return cell.bounds.size.height;
}
https://stackoverflow.com/questions/39917966
复制相似问题