Home > Software engineering >  Xcode 13 update height UITableViewCell
Xcode 13 update height UITableViewCell

Time:10-20

tell me how you can fix this behavior in xcode 13, updating the cell height does not work. In xcode 12.5.1 works fine 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)
}

CodePudding user response:

maybe you need to reload a specific cell/cells, and they will take their new height

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

CodePudding user response:

This is not an issue with Xcode 13 -- it's an issue with iOS 15

Apparently (based on quick testing), heightForRowAt treats zero-height rows as "non-visible rows" and so it is not called for that row if you've set it's height to Zero.

You can try to get around this by setting the row height to 0.01 instead:

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