UITableView Section Header not showing

Check if a tableView delegate is connected


Try this out for UITableView Section Header.

  1. Programatically create headerview

    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = UIView.init(frame: CGRectMake(0, 0, tblView.bounds.size.width, 50))
        let lblHeader = UILabel.init(frame: CGRectMake(15, 13, tableView.bounds.size.width - 10, 24))
        if section == 0 {
            lblHeader.text = "Image Settings"
        }
        else if section == 1 {
            lblHeader.text = "Personal Settings"
        }
        else {
            lblHeader.text = "Other Settings"
        }
        lblHeader.font = UIFont (name: "OpenSans-Semibold", size: 18)
        lblHeader.textColor = UIColor.blackColor()
        headerView.addSubview(lblHeader)
        headerView.backgroundColor = UIColor(colorLiteralRed: 240.0/255.0, green: 240.0/255.0, blue: 240.0/255.0, alpha: 1.0)
        return headerView
    }
    
  2. Height for HeaderView

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