0

我从xib加载单元。我在单元格中添加了 3 个垂直分隔符(尝试从 xib 和代码中添加)。在我选择单元格之前一切正常。当我选择卖出时,分隔符消失了。

以下是图片: 未选中: 在此处输入图像描述

已选中 在此处输入图像描述

添加分隔符的代码:

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.topSeparator = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 1)] autorelease];
        [self addSubview:topSeparator];

        self.bottomSeparator = [[[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height - 1, self.bounds.size.width, 1)] autorelease];
        [self addSubview:bottomSeparator];

        // Initialization code
        CGFloat xOffset = 314;
        UIView *imageView1 = [[[UIView alloc] initWithFrame:CGRectMake(xOffset, 0, 1, self.bounds.size.height)] autorelease];
        imageView1.tag = kTagBorder1;
        imageView1.backgroundColor = [UIColor blackColor];
        [self addSubview:imageView1];

        xOffset = 487;
        imageView1 = [[[UIView alloc] initWithFrame:CGRectMake(xOffset, 0, 1, self.bounds.size.height)] autorelease];
        imageView1.tag = kTagBorder2;
        imageView1.backgroundColor = [UIColor blackColor];
        [self addSubview:imageView1];

        xOffset = 573;
        imageView1 = [[[UIView alloc] initWithFrame:CGRectMake(xOffset, 0, 1, self.bounds.size.height)] autorelease];
        imageView1.tag = kTagBorder3;
        imageView1.backgroundColor = [UIColor blackColor];
        [self addSubview:imageView1];
    }
    return self;
}

我什至试过这个:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    [self bringSubviewToFront:[self viewWithTag:kTagBorder1]];
    [self bringSubviewToFront:[self viewWithTag:kTagBorder2]];
    [self bringSubviewToFront:[self viewWithTag:kTagBorder3]];
    [self setNeedsDisplay];

    // Configure the view for the selected state
}
4

2 回答 2

0

您不应将这些行添加为self( UITableViewCell) 的子视图。相反,将其添加为self.contentView- 的子级,它是包含UITableViewCell.

本文包含有关如何正确自定义 UITableView 的提示

于 2012-08-16T10:27:58.427 回答
0

我修好了它。我使用带有黑色图像的 UIImageView 而不是带有黑色背景的 uiview。在这种情况下,视图不会消失。

于 2012-08-17T09:20:17.560 回答