gpt4 book ai didi

ios - 如何根据可变高度 UITableView 内的内容确定 UIWebView 高度?

转载 作者:行者123 更新时间:2023-11-29 00:39:11 26 4
gpt4 key购买 nike

我有一个 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 加载的,它只是一个包含 UIWebViewUITableViewCell。 (如果单元格只是将自己调整为最大的 html 内容,那也很好,尽管可变高度会更好)。

最佳答案

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath { 
UITableViewCell *cell = [self tableView: tableView cellForRowAtIndexPath: indexPath];
return cell.bounds.size.height;
}

关于ios - 如何根据可变高度 UITableView 内的内容确定 UIWebView 高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39917966/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com