我想在我的 UIViewController 中使用 tableview,并且我想使用“tableHeaderView”,但我相信默认情况下,tableHeaderView 是“nil”
有没有办法初始化它?或者换句话说,如何在 UIViewController 中使用“tableHeaderView”?
谢谢
最佳答案
如果你想为整个表格 View 制作标题,那么你会想做这样的事情
override func viewDidLoad() {
super.viewDidLoad()
let header = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 10))
header.backgroundColor = UIColor.blackColor()
tableView.tableHeaderView = header
}
或者如果你想在表格 View 的一部分中添加标题,你可以这样做
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
//give height for header
return 10
}
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//you want to provide your view here
return nil
}
关于ios - UIViewController 中的 tableHeaderView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35188369/