问题
I'm having a really weird issue with table view separators. I have set the separator color to a dark gray which works great below the cells, but for some reason, there is a white separator before my section header (see the screenshot, above November). When I set the separator style to none, the line disappears which indicates that it is a separator. How can I remove this white separator line?

回答1:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, -1, 320, 2)];
view2.backgroundColor = [UIColor blackColor]; // Your color
view1.backgroundColor = [UIColor blackColor]; // Your color
[view1 addSubview:view2];
return view1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.01;
}
回答2:
For me, this fixed it:
cell.backgroundColor = .clear
I was setting the cell’s backgroundView
, but apparently the cell’s default color was shining through in some cases.
来源:https://stackoverflow.com/questions/25330784/white-separator-above-table-section-headers