UITableView Section Header not showing UITableView Section Header not showing swift swift

UITableView Section Header not showing


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}


Actually it's working.my mistake was to believe that didSet{} was also called within the class -> it's not the case.

When I was setting the title in the init() it was not setting the label text.