tableView.dequeueReusableHeaderFooterView(withIdentifier: ) crashes on iPad only

I have created a custom class:

class TarifsHeaderFooterView: UITableViewHeaderFooterView { …}

With its init:

override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
configureContents()
}

I register the custom header view in viewDidLoad of the class using the tableView. Table delegate and data source are defined in storyboard.

tarifsTableView.register(TarifsHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: headerTarifsIdentifier)

And call it:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: headerTarifsIdentifier) as! TarifsHeaderFooterView

That works on iPhone (simulators and devices).

But it crashes on any iPad simulator, as tableView.dequeueReusableHeaderFooterView(withIdentifier: headerTarifsIdentifier) is found nil.

What difference between iPhone and iPad do I miss that explains this crash ?

PS: sorry for the messy message. It looks like the new "feature" of the forum to put a Copy code button on the code parts, causes the code sections to be put at the very end of the post, not at the place they should be.

Accepted Answer

Found it. My mistake.

I had a test for iPad in the viewDidload.

I inadvertently put the register in the iOS section ; so it did not apply for iPad !

tableView.dequeueReusableHeaderFooterView(withIdentifier: ) crashes on iPad only
 
 
Q