【问题标题】:Grouped UITableView's cell separator missing when setting backgroundView with an image使用图像设置 backgroundView 时缺少分组的 UITableView 的单元格分隔符
【发布时间】:2012-09-06 15:36:19
【问题描述】:

我有一个带有自定义 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; 
}

【问题讨论】:

    标签: ios5 uitableview


    【解决方案1】:

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

    一切顺利。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      • 2015-09-17
      • 2011-02-09
      • 1970-01-01
      • 2019-05-02
      • 1970-01-01
      相关资源
      最近更新 更多