Home > Back-end >  Hiding header of UITableView
Hiding header of UITableView

Time:05-26

I have TableView with invisible header. I already tried unsuccessfully to hide the header with:

tableView.tableHeaderView = .init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))

tableView.tableHeaderView?.removeFromSuperview()

tableView.tableHeaderView = nil

But I found out that if you call a multitask or manually change the theme to dark/light, this header disappears

Here is an example

So, is this a bug, or I missing something?

CodePudding user response:

This code works perfectly

tableView.tableHeaderView = .init(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))

CodePudding user response:

This Works For me

var frame = CGRect.zero
frame.size.height = .leastNormalMagnitude
tableViewname.tableHeaderView = UIView(frame: frame)

also this will work in single line [answer by @getmemd]

CodePudding user response:

You can try this for table header

tableView.tableHeaderView = UIView(frame: .zero)

Also if you want to hide header for section then you can achieve with below tableview delegate methods.

func tableView(_: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return nil
}

func tableView(_: UITableView, heightForHeaderInSection _: Int) -> CGFloat {
    return 0
}

CodePudding user response:

You can use without frame

 tableView.tableHeaderView = UIView()
  • Related