【问题标题】:UITableView within UITableViewCell with AutoDimension带有 AutoDimension 的 UITableViewCell 中的 UITableView
【发布时间】:2018-07-10 12:06:07
【问题描述】:

我想在 UITableViewCell 中实现 UITableview。唯一的条件是我需要对两个表都使用 UITableViewAutomatic Dimension。给出一个固定高度可以正常工作,但我不知道如何使用 UITableViewAutomatic 尺寸实现。

【问题讨论】:

    标签: ios swift uitableview autolayout


    【解决方案1】:

    你需要两个步骤

    1- 在viewDidLoad

    tableView.estimatedRowHeight = 120 // initial height to help auto-layout such as current cell height in xib  
    tableView.rowHeight = UITableViewAutomaticDimension
    

    2- 创建从上到下适当约束的单元格,以便自动布局可以推断它在运行时的真实高度

    也可以查看tutorial

    【讨论】:

    • 单元格高度取决于内部表格视图的内容大小。我已将顶部、底部、领先、训练归零。
    • 约束的设置方式应使您能够从应用的垂直约束中分辨出高度。在您的情况下,您应该将tableViewtopAnchorbottomAnchor 设置为tableViewCell 的contentView,并使用heightAnchor 指定高度
    • 这是我使用高度约束的问题,然后我必须提前获取内部表格视图的高度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-30
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多