相关疑难解决方法(0)

在 UIViewAlertForUnsatisfiableConstraints 中使用 Autolayout 结果的可扩展 UITableView Cell

我正在尝试使用UITableViewAutomaticDimension行高和单元格自动布局的组合来制作可扩展单元格。为了让事情变得简单,我从以下简单的代码开始,我希望它可以工作:

import UIKit

class ViewController: UITableViewController {

    let cells = [Cell(), Cell(), Cell()]

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 50

        for cell in cells {
            cell.tableView = tableView
        }
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return cells[indexPath.row]
    }
}

class Cell: UITableViewCell { …
Run Code Online (Sandbox Code Playgroud)

uitableview ios autolayout swift

2
推荐指数
1
解决办法
564
查看次数

标签 统计

autolayout ×1

ios ×1

swift ×1

uitableview ×1