我正在使用自调整大小的 UITableViewCell
,里面有一些标签,所有标签的行号都是 0。
tableView.estimatedRowHeight = 284
tableView.rowHeight = UITableViewAutomaticDimension
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SearchCell", for: indexPath) as! NodeCell
let nodemodel = nodes[indexPath.row]
cell.like.text = Utils.convert_string(string: String(nodemodel.like))
cell.address.text = nodemodel.address
cell.avatar.downloadedFrom(link: "www.example.com")
cell.avatar.layer.cornerRadius = cell.avatar.frame.size.width / 2
cell.avatar.layer.borderWidth = CGFloat(integerLiteral: 1)
cell.avatar.layer.borderColor = UIColor.black.cgColor
cell.avatar.clipsToBounds = true
cell.title.text = nodemodel.node_name
cell.layoutIfNeeded()
return cell
}
运行应用程序后,我的所有标签都仅限于单行,文本不会完全显示,直到滚动一些项目然后滚动回来。怎么了?我在返回单元格之前执行了 layoutIfNeeded()
但它不起作用
最佳答案
将 UIStackView
分布模式从 Fill Proportionally
更改为 Equal Spacing
后问题得到解决
关于ios - 在滚动某些项目之前, self 调整单元格无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42852387/