2012-08-16 55 views
0

我从xib加载单元格。我向单元中添加了3个垂直分隔符(试图从xib和代码中添加)。一切都还好,直到我选择了细胞。当我选择卖出时,分隔符消失。UITableViewCell子查询问题

以下是图像: 未选择: enter image description here

选择添加分隔的 enter image description here

代码:

- (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 
} 

回答

0

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