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;
}
When you give subView to your cell it will automatically hide the separator. So try to add the separator line to your image itself. So it will give you the separator look.
All the best.