如果有人能帮我解决以下问题,我会很高兴。
我正在尝试使用不同的动态单元构建 UITableViewController 。 任何单元格都有不同的高度,因此我覆盖了 UITableViewDelegate 的 heightForRow 并返回 UITableViewAutomaticDimension。
到那时,对于我添加到 UITableView 中的每个单元格,一切都很好,直到我尝试添加以下附加单元格: Cell example .
在运行时,调用了下面单元格的 heightForRow,内部 UITableView 的高度为 0,因为 UITableViewAutomaticDimension 没有考虑它的高度。
我的问题是外部的 heightForRow 如何考虑具有不同动态行高的内部 UITableView?
感谢您的帮助:)
最佳答案
您可以使用UITableViewDelegate方法来支持高度
// Variable height support
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
您可以计算内部表格高度并在此处返回:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// check if table view is the outertable view in case you have the same delegate
// let customCellHeight = number of subCells * heightOfSubCell + padding;
return customCellHeight;
}
关于swift - 自动调整 UITableViewCell 内部 UITableView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52856102/