0

I have two question

1.) I want to add multiple controls in UITableViewHeader section for that I have use below code but I am not able to add button in view

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let view = UIView()
    view.backgroundColor = #colorLiteral(red: 0.8197316527, green: 0.2123814821, blue: 0.1997521222, alpha: 1)
    let button = UIButton()
    button.setTitle("Hello", for: .normal)
    button.titleLabel?.text = "Hello"
    view.addSubview(button)
    return view
}

2.) How can I add multiple custom header section from Storyboard

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0
let button = UIButton()
button.setTitle("Hello", for: .normal)
button.titleLabel?.text = "Hello"

The last line is illegal so delete it. — Your button has no frame so you can’t see it. At least give it a size:

button.sizeToFit()

(Another problem is that you should not be creating a view like this. You should be registering and dequeuing a table view header/footer.)

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks it worked. Do you have any idea how can I add custom headers from UIStoryboard –  Dec 22 '18 at 19:22
  • One question at a time please. Might want to see https://stackoverflow.com/questions/36926612/swift-how-creating-custom-viewforheaderinsection-using-a-xib-file – matt Dec 22 '18 at 19:24