I have a grouped table view with a few sections. By default, there is gap between the sections. I've been looking around for a simple way to remove the gap completely without any luck. The best I could do through the Interface Builder is to set the "Section Height" values in the "Table View Size" property section, but these fields do not accept 0 as valid input. Can anyone tell me the best way to sort this out?
2 Answers
The above answer for me did not work, I had to actually create a UIView with a height of 1 and a background color of clear and then set it's y origin coordinate to -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; } This gave me a Grouped tableView where the section cells would not scroll underneath the headerView and not have padding in-between the sections.
Comments
In your table view's delegate, 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; }