ビューコントローラーの上部に、表がスクロールされても消えない2つのヘッダーが必要です。ViewForHeaderInSectionの2つのヘッダー
最初のコードセクションには、私が持っているトップヘッダーがviewDidLoad
に表示されます。 viewForHeaderInSection
は正しく動作します。 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
}
1つの以上のビューを追加したい場合は、** 1 ** viewForHeaderで加算2つのビューをしたいですか?または、各セクションに1つのヘッダーと*全体の* tableviewの1つのヘッダーが必要ですか? – Honey
1つのviewForHeaderに2つのビューを一緒に追加します。 'v'に –
ありがとうございます.2つのサブビューを追加することができます。1)あなたのセグメントコントロール2)赤いビュー –