I want two headers at the top of the view controller that does not disappear as the table is scrolled.
The first section of code displays a top header that I have in viewDidLoad
. The viewForHeaderInSection
works correctly. How do I add the header to the viewForHeaderInSection
?
let header = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 100))
header.backgroundColor = UIColor.red
//header.addSubview(header)
tableView.tableHeaderView = header
/////////
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let v = UIView()
v.backgroundColor = UIColor.white
let segmentControl = UISegmentedControl(frame: CGRect(x: 10, y: 5, width: tableView.frame.width, height: 30))
segmentControl.insertSegment(withTitle: "one", at: 0, animated: false)
segmentControl.insertSegment(withTitle: "two", at: 1, animated: false)
segmentControl.insertSegment(withTitle: "three", at: 2, animated: false)
v.addSubview(segmentControl)
return v
}