[英]Section header title lost when customize the section header view
在我的代碼中,我使用以下代碼來設置tableview的節標題。 而且效果很好。
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int)
-> String? {
//return self.adHeaders[section]
return self.headers[section]
}
我想自定義標題的背景色,所以我在上面的代碼之前插入下面的代碼。
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView()
headerView.backgroundColor = UIColor(red: 232/255.0, green: 237/255.0, blue: 242/255.0, alpha: 1.0)
return headerView
}
結果,背景顏色改變,而標題文本丟失。
當您實現viewForHeaderInSection
, titleForHeaderInSection
不會調用titleForHeaderInSection
。 因此,您需要在viewForHeaderInSection
設置標題視圖的viewForHeaderInSection
。 您可能需要創建一個UILabel。
您還必須實現heightForHeaderInSection
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.