今天在使用swift中设置UITableView的section head的高度时第一个section总是不对。
方法是
// tableView.estimatedSectionFooterHeight = 0
// tableView.estimatedSectionHeaderHeight = 0
设置代理方法
// func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
// return 10;
// }
//
// func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
// return 0.01;
// }


解决方法:以上代码全部注释掉,特别是委托方法必须注释
添加如下代码
tableView.tableHeaderView = UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0.1)) 这一行的高度必须设置
tableView.sectionHeaderHeight = 10;
tableView.sectionFooterHeight = 0.01;
网友评论