簡體   English   中英

自定義節標題視圖時,節標題標題丟失

[英]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
}

結果,背景顏色改變,而標題文本丟失。

當您實現viewForHeaderInSectiontitleForHeaderInSection不會調用titleForHeaderInSection 因此,您需要在viewForHeaderInSection設置標題視圖的viewForHeaderInSection 您可能需要創建一個UILabel。

您還必須實現heightForHeaderInSection

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM