skip to Main Content

I have a tableview with this awkward gap between the top of the first section and the nav bar. I tried the following solutions I found online to hide the section but none seem to be working here:

tableView.tableHeaderView?.frame = CGRect.zero

also tried adding

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

Neither seem to work. Any suggestions?

enter image description here

2

Answers


  1. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        return CGSize.zero
    }
    
    Login or Signup to reply.
  2. Put this in viewDidLoad:

    if #available(iOS 15.0, *) {
        yourTableView.sectionHeaderTopPadding = 0
    } else {
        UITableView.appearance().sectionHeaderTopPadding = CGFloat(0)
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search