How to remove vertical spacing between sections of a UITableView?

I have a grouped table view with several partitions. By default, there is a gap between sections. I was looking for an easy way to completely remove the gap without any luck. The best I could do with Interface Builder is to set the "Section Height" values ​​in the "Table Size" properties section, but these fields do not accept 0 as valid input. Can someone tell me the best way to figure this out?

+3
source share
2 answers

In the delegate view of the table, you can implement tableView:heightForHeaderInSection:and tableView:heightForFooterInSection:.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0;
}
+1
source

, UIView 1 , y- -1.

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -1, tableView.frame.size.width, 1)];
    [view setBackgroundColor:[UIColor clearColor]];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}

Grouped tableView, headerView .

+2

All Articles