Incorrect Content Size in UITableView grouped style

HI, ContentSize is incorrect in UITableView grouped style in iOS15.4, I run this below code in iOS 15.4 using Xcode 13.1 which has the content size 40 (cell 0 height + cell 1 height), and it works fine. But in the Xcode 13.3.1 content size is approximately 60.

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
   
  lazy var tableView: UITableView = {
    let tableView = UITableView(frame: .zero, style: .grouped)
    tableView.backgroundColor = UIColor.lightGray
    tableView.sectionHeaderTopPadding = 0.01
    tableView.delegate = self
    tableView.dataSource = self
    tableView.translatesAutoresizingMaskIntoConstraints = false
    tableView.register(TableViewCell.self, forCellReuseIdentifier: "TableViewCell")
    return tableView
  }()

  override func viewDidLoad() {
    super.viewDidLoad()
     
    self.view.addSubview(tableView)
     
    tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
    tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
    tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
    tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
  }
   
   
  //MARK: UITableViewDataSource & UITableViewDelegate
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 2
  }
   
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell") as! TableViewCell
     
    return cell
  }

  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 20
  }
   
  func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return nil
  }
   
  func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return CGFloat.leastNormalMagnitude
  }
   
  func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    return nil
  }
   
  func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return CGFloat.leastNormalMagnitude
  }
   
}


class TableViewCell: UITableViewCell {
   
  override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    self.backgroundColor = .red
  }
   
  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}
Post not yet marked as solved Up vote post of Jk398 Down vote post of Jk398
800 views