swift - 自动调整 UITableViewCell 内部 UITableView 的大小

标签 swift uitableview autosize

如果有人能帮我解决以下问题,我会很高兴。

我正在尝试使用不同的动态单元构建 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/

相关文章:

ios - 如何在紧凑型设备上快速正确使用 splitViewController 中的 didSelectRowAt ?

ios - 如何使用 swift 将批量数据插入 iOS 中的 SQLite 数据库

ios - 无法将类型 'NSRange'(又名 '_NSRange')的值转换为预期类型 'Range<Index>'(又名 'Range<String.CharacterView.Index>')

ios - 使用自动布局支持以编程方式更改 UITableView 位置

c# - 是否可以指定 Windows 窗体控件相对于另一个 AutoSize 控件的位置?

ios - 我无法在 Swift 中解决 "Use of undeclared type ' SphereNode'"

xcode - didSelectRowAtIndexPath 中的详细信息项显示为 null

ios - 当VC从另一个VC返回时,如何清除UITableVIew中的所有检查?

javascript - 创建输入字段,例如 Google 联系人

c# - DataGridView虚拟模式列分隔符双击自动调整大小