Bug with UITableViewHeaderFooterView in Xcode 13.3

I just downloaded Xcode 13.3 (building for iOS 15.4), and came across a strange issue related to using a UITableViewHeaderFooterView.

If I return a non-nil UITableViewHeaderFooterView in the delegate method tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) for the FIRST section of a GROUPED UITableView, that typical initial padding that is usually present at the top of the grouped UITableViews, goes away entirely.

Separately, if I return nil in that same method, that typical initial padding is present, but it's noticeably reduced.

BUT, if I return a non-nil regular UIView(), the padding is present, and it is the exact same amount as is usually present on previous Xcode/iOS versions.

Has anyone come across this?

I just created a brand new app project, and I am able to recreate the issue. Something definitely changed with the SDK.

If I use the below code, WITHOUT tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? implemented at all, the typical top grouped UITableView padding is there.

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    private var tableView = UITableView(frame: .zero, style: .grouped)

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.title = "Testing"
        navigationItem.largeTitleDisplayMode = .never

        let tableView = UITableView(frame: .zero, style: .grouped)
        view.addSubview(tableView)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "reuse")

        tableView.translatesAutoresizingMaskIntoConstraints = false
        tableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
        tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
        tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
        tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "reuse")!
        cell.textLabel?.text = "Test"
        return cell
    }
}

However, if I simply implement that method the padding either gets deleted completely, or gets reduced (see attached screenshots).

For example, returning a simple UILabel gets rid of the padding, as below:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
   let label = UILabel()
   label.text = "Test"
   return label
}

This definitely wasn't the case on previous Xcode/iOS 15 versions.

FWIW i'm also experiencing this issue, and thus far, the only solution has been to add back in the padding manually. No real input on the underlying cause.

Bug with UITableViewHeaderFooterView in Xcode 13.3
 
 
Q