【问题标题】:Xcode 13 update height UITableViewCellXcode 13 更新高度 UITableViewCell
【发布时间】:2021-12-06 15:10:59
【问题描述】:

告诉我如何在 xcode 13 中解决此问题,更新单元格高度不起作用。在 xcode 12.5.1 中工作正常 https://www.icloud.com/iclouddrive/0Wq4Ml4Zl_0Hk4XcQxrQ3FIwg#TableView

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if isHideCell && indexPath.row == 1 {
        return 0
    } else {
        return tableView.rowHeight
    }
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    guard indexPath.row == 0 else { return }
    isHideCell = !isHideCell
    tableView.performBatchUpdates(nil)
    tableView.deselectRow(at: indexPath, animated: true)
}

【问题讨论】:

    标签: ios swift uitableview uikit


    【解决方案1】:

    这不是 Xcode 13 的问题 -- 这是 iOS 15

    的问题

    显然(基于快速测试),heightForRowAt 将零高度行视为“不可见行”,因此 为该行调用如果您已将其高度设置为零。

    您可以尝试通过将行高设置为 0.01 来解决此问题:

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if isHideCell && indexPath.row == 1 {
            return 0.01
        }
        return tableView.rowHeight
    }
    

    【讨论】:

      【解决方案2】:

      也许您需要重新加载特定的单元格/单元格,它们会采用新的高度

      tableView.reloadRows(at: [IndexPath], with: UITableView.RowAnimation)
      

      【讨论】:

      • 这个方案不合适,有时我会结合textField这样的高度变化,这样的话键盘会被隐藏
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-05
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      • 2013-06-15
      • 2014-11-23
      • 1970-01-01
      相关资源
      最近更新 更多