Grouped UITableView's cell separator missing when setting backgroundView with an image
Posted
by
Howard Spear
on Stack Overflow
See other posts from Stack Overflow
or by Howard Spear
Published on 2012-09-06T15:36:19Z
Indexed on
2012/09/06
15:37 UTC
Read the original article
Hit count: 209
I have a grouped UITableView with a custom UITableViewCell class and I am adding a custom background image to each cell. However, when I do this, the cell's separator is not visible. If simply switch the table style to Plain instead of Grouped, the separator is showing up.
I need the grouped table - how do I make the separator show up?
Here's my code:
@interface MyCustomTableViewCell : UITableViewCell
@end
@implementation MyCustomTableViewCell
// because I'm loading the cell from a xib file
- (id)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self)
{
// Create a background image view.
self.backgroundView = [[UIImageView alloc] init];
}
return self;
}
// MyViewController
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//
// standard cell dequeue + create cell code here
//
//
// Configure the cell background now
//
UIImage *backgroundImage = [UIImage imageNamed:@"odd_row.png"];
if (indexPath.row % 2 == 0)
{
backgroundImage = [UIImage imageNamed:@"even_row.png"];
}
UIImageView *backgroundView = (UIImageView *)cell.backgroundView;
backgroundView.image = backgroundImage;
}
© Stack Overflow or respective owner