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?

1

4 Answers 4

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;
0

have you tried setting seperator style to none?

tableview.separatorType = UITableViewCellSeparatorStyleNone
0
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?

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.