我曾经遇到过同样的问题,通过在传递给viewForHeaderInSection
方法时将相同的颜色设置为标题视图来解决了这个问题。我是从storyboard中加载标题视图的,在storyboard中更改颜色并没有解决我的问题,但是在传递给viewForHeaderInSection
时编程更改颜色却解决了问题。
以下是片段代码。
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
// You can load 'headerView' from xib or storyboard
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 50))
headerView.backgroundColor = UIColor(r: 248, g: 248, b: 248, a: 0.94)
return headerView
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}