4

I have UITableViewCells in the same section which have gaps between them. I coloured each cell's contentView background and did an NSLog to show that it's the same height as the cells.

Still, there's a gap between them. They're definitely in the same section as each other. Any ideas as to what could be causing the gap?

Andrew
  • 15,935
  • 28
  • 121
  • 203

4 Answers4

7

I'm not sure if you have used this:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 78;
}

And Checked that the Cell really is 78(just for arguments sake) in IB. And then use:

tableView.sectionHeaderHeight = 0.0;

And set the style of the tableView:

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

And the last solution I've bumped into over the years is that sometimes you need to extend your background image with a pixel for some reason. I don't think this is a good solution at all, cause it doesn't really address the real problem, but rather puts a crappy bandaid on it.

cellFrameBackground.size.height += 1;
Leeloo Levin
  • 443
  • 2
  • 7
0

have you tried setting seperator style to none?

tableview.separatorType = UITableViewCellSeparatorStyleNone
ethyreal
  • 3,659
  • 2
  • 21
  • 25
0

If you are talking about a 1 pixel gap, that is the cell separator. You can remove this by setting a property on the table view:

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

If you wanted to change the color of that separator use the separatorColor property.


If you are talking about a gap bigger than 1 pixel, can you post a screenshot and your cell code?

jszumski
  • 7,430
  • 11
  • 40
  • 53
0

To add to the set of great answers, sometimes you just need to extend the background height as mentioned by Leeloo:

cellFrameBackground.size.height += 1;

Then, make your cell clip to bounds:

cell.clipsToBounds = YES;

And, voila.

Kelsey
  • 541
  • 3
  • 11