之前一直以為設置-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section和-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;就行了。在iOS15以下的版本沒問題,但是發現在iOS15以上還是會有20的像素高度。困擾了好長時間。后來查閱資料才知道,iOS15新增了屬性。
?iOS 15 的 UITableView又新增了一個新屬性:sectionHeaderTopPadding 會給每一個section header 增加一個默認高度
當我們 使用 UITableViewStylePlain 初始化 UITableView的時候,就會發現,系統給section header增高了22像素。
//解決辦法
? ? if (@available(iOS 15.0, *)) {
?? ? ? self.tableView.sectionHeaderTopPadding = 0;
? ? }