_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
iOS開發(fā)中, UITableView style 設(shè)置為 UITableViewStyleGrouped 樣式的時(shí)候,間距一般都不是我們想要的,為了自定義section之間的間距可以使用如下兩個(gè) UITableViewDelegate 方法:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 8;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.1;
}
在 iOS11 之前基本就可以了,但是在iOS 11 之后需要再添加如下兩個(gè) UITableViewDelegate 方法才可以出效果:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc]init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc]init];
}