1

我有一个带有自定义 UITableViewCell 类的分组 UITableView,并且我正在向每个单元格添加自定义背景图像。但是,当我这样做时,单元格的分隔符不可见。如果只是将表格样式切换为普通而不是分组,则会显示分隔符。

我需要分组表 - 如何显示分隔符?

这是我的代码:

@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; 
}
4

1 回答 1

1

当您将 subView 提供给您的单元格时,它将自动隐藏分隔符。因此,尝试将分隔线添加到图像本身。所以它会给你分隔符的外观。

一切顺利。

于 2012-09-07T18:48:22.807 回答