我从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
}