Swift - how to make custom header for UITableView?

后端 未结 7 761
说谎
说谎 2020-12-23 13:57

I need to add custom header to my table

I try this

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    l         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 14:12

    If you are using custom cell as header, add the following.

    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    
            let headerView = UIView()
            let headerCell = tableView.dequeueReusableCell(withIdentifier: "customTableCell") as! CustomTableCell
            headerView.addSubview(headerCell)
            return headerView
        }
    

    If you want to have simple view, add the following.

    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerView:UIView =  UIView()
        return headerView
    }
    

提交回复
热议问题