小编Mic*_*hal的帖子

具有动态高度的 UITableViewCell 内的 UITableView

我需要将 UITableView 放在带有自动布局的 UITableViewCell 中,因为第二个表有不同的行数,而一行可以有不同的高度。
这是我的视图控制器

class ViewController: UIViewController {

    let tableView = UITableView()
    let cellId = "firstTableCellId"

    override func viewDidLoad() {
        super.viewDidLoad()
        setupView()
        tableView.reloadData()
        view.backgroundColor = UIColor.gray
    }

    func setupView() {
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        tableView.register(NextTable.self, forCellReuseIdentifier: cellId)
        tableView.backgroundColor = UIColor.green
        tableView.separatorStyle = .singleLine

        view.addSubview(tableView)
        view.addConstraintsWithFormat("V:|-60-[v0]-5-|", views: tableView)
        view.addConstraintsWithFormat("H:|-8-[v0]-8-|", views: tableView)
    }
}

extension ViewController: UITableViewDelegate {

}

extension ViewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2 …
Run Code Online (Sandbox Code Playgroud)

uitableview uikit ios autolayout swift

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

标签 统计

autolayout ×1

ios ×1

swift ×1

uikit ×1

uitableview ×1