Home > Blockchain >  Can't hide tableview header area
Can't hide tableview header area

Time:10-30

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

CodePudding user response:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
    return CGSize.zero
}

CodePudding user response:

Put this in viewDidLoad:

if #available(iOS 15.0, *) {
    yourTableView.sectionHeaderTopPadding = 0
} else {
    UITableView.appearance().sectionHeaderTopPadding = CGFloat(0)
}
  • Related