ios - 在滚动某些项目之前, self 调整单元格无法工作

标签 ios swift uitableview

我正在使用自调整大小的 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() 但它不起作用 enter image description here

最佳答案

UIStackView 分布模式从 Fill Proportionally 更改为 Equal Spacing 后问题得到解决

关于ios - 在滚动某些项目之前, self 调整单元格无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42852387/

相关文章:

ios - 如何在 swift iOS 上做一个简单的分分钟倒计时?

ios - 无法分配给 UITableViewCell 中的 'accessoryType'

ios - 滚动时 UITableViewCell 内容发生变化,因为在其中一个单元格中运行计时器

ios - 无法通过下拉刷新 tableview Controller 中的刷新我的 JSON 数据

ios - 不符合协议(protocol) UIPickerViewDataSource

ios - 应用程序在后台时的远程推送通知 swift 3

ios - Swift - 无法从 Firebase 数据库中检索数据

ios - Alamofire 模块不使用 Swift 3.0.1 编译

ios - 我的应用程序的公共(public)文件夹

iphone - 通过 NSRegularExpression 获取 Javascript 函数之间的特定值?