This seems like an easy problem, but I've hit a brick wall finding a solution and I'm hoping someone on here can help...
I am making a UITableView using UITableViewStyleGrouped, and I am seeing a small (1 pixel) white line between the first and second row of every section of my table view (see image)
It seems that the reason for this line is that the first cell in each section is 1 pixel taller than the others. When I set the initial cell of each group to be 29 pixels high (the others are 30) the gap disappears and all is well.
While this is workaround is successful, I'd rather know the reason for this occurring so I can avoid using a messy hack.
FYI:
- I have made sure this is not an issue with the background images I have by using - they are all 30px high, and I have replaced the top image with a middle image with the same result.
- I have removed all borders between the cells by setting separatorStyle = UITableViewCellSeparatorStyleNone
- This effect doesn't happen on UITableViewStylePlain
Any help is greatly appreciated.
Thanks
Code for table setup:
myTable = [[UITableView alloc] initWithFrame:CGRectMake(TABLE_SHIFT_OFFSET,
DATE_SLIDER_HEIGHT - DATE_SLIDER_SHADOW_HEIGHT,
326,
self.view.frame.size.height - DATE_SLIDER_HEIGHT + DATE_SLIDER_SHADOW_HEIGHT) style:UITableViewStyleGrouped];
myTable.backgroundColor = [UIColor clearColor];
myTable.backgroundView = nil;
myTable.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:myTable];
myTable.dataSource = self;
myTable.delegate = self;
Code for cell setup:
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// This is a hack to make sure that a white line doesnt appear between the
// first and second rows in the table, which happens for reasons I dont understand
if (indexPath.row == 0) {
return 29;
}
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"satCell"];
if (!cell)
{
cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"satCell"];
}
cell.backgroundView = nil;
cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
cell.backgroundColor = [UIColor whiteColor];
int numberOfRowsInThisSection = [self tableView:tableView numberOfRowsInSection:indexPath.section];
if (numberOfRowsInThisSection == 1)
{
cell.backingImage = self.singleWhite;
}
else if (indexPath.row == 0)
{
cell.backingImage = self.topWhite;
}
else if (indexPath.row % 2 == 0)
{
// Even row
if (indexPath.row == numberOfRowsInThisSection - 1)
{
// Last row (even)
cell.backingImage = self.botWhite;
}
else
{
// Normal row (even)
cell.backingImage = self.midWhite;
}
}
else if (indexPath.row % 2 == 1)
{
// Odd row
if (indexPath.row == numberOfRowsInThisSection - 1)
{
// Last row (even)
cell.backingImage = self.botDark;
}
else
{
// Normal row (odd)
cell.backingImage = self.midDark;
}
}
// Setup cell text [REMOVED FOR BREVITY]
return cell;
}
The code for setting the backing Image within MyTableViewCell:
- (void)setBackingImage:(UIImage *)backingImage
{
if (self.backingImage != backingImage)
{
_backingImage = nil;
_backingImage = backingImage;
self.backingView.image = backingImage;
}
}
self.backingView is set up using the following code:
[[UIImageView alloc] initWithFrame:CGRectMake(7, 0, 307, 30)];