0
我有我的代码如何给动态高度UITableView的
tableView = UITableView(frame: CGRect(x:0,y:0,width:0,height:0))
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellReuseIdentifier")
tableView.delegate = self
tableView.dataSource = self
tableView.translatesAutoresizingMaskIntoConstraints = false
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return comments.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:UITableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "cellReuseIdentifier") as UITableViewCell!
cell.textLabel?.text = self.comments[indexPath.row]
return cell
}
一个UITableView
,我想给一个动态的高度,这UITableView.I试过两件事情
tableView.estimatedRowHeight = 88.0
tableView.rowHeight = UITableViewAutomaticDimension
tableView.heightAnchor.constraint(equalToConstant: tableView.contentSize.height).isActive = true
,没有他们工作。
我只有顶部,左,右的约束,而不底部'UITableView'和细胞内的,我不除文本外,还有其他任何内容 – sakoaskoaso
您还需要设置底部约束。否则,你的tableViewcell将不能正确调整大小。 –
但这会自动定义它的高度不是吗?我试图将它的底部固定到它的父级UIView,并将它调整到父级的高度 – sakoaskoaso