Cocoa touch 自定义UITableViewCell中的selectedBackgroundView

Cocoa touch 自定义UITableViewCell中的selectedBackgroundView,cocoa-touch,ios4,uitableview,Cocoa Touch,Ios4,Uitableview,因此,我直接从nib文件加载了一个单元格: NSArray *cellContents = [[NSBundle mainBundle] loadNibNamed:@"ResultsTableViewCell" owner:self options:nil]; cell = [cellContents objectAtIndex:0]; 在nib文件中,有一个UITableViewCell和两个UIView,每个UIView都有自己的子视图。结构: -TableViewCell

因此,我直接从nib文件加载了一个单元格:

NSArray *cellContents = [[NSBundle mainBundle] loadNibNamed:@"ResultsTableViewCell" owner:self options:nil];
        cell = [cellContents objectAtIndex:0];
在nib文件中,有一个UITableViewCell和两个UIView,每个UIView都有自己的子视图。结构:

-TableViewCell
   Label 1
   Label 2
-UIView A
   UIView a
   UIView b
   UIImageView c
   UIImageView d
-UIView B
   UIView e
   UIView f
   UIImageView g
   UIImageView h
因此UIView A连接到UITableViewCell的backgroundView属性,UIView B连接到selectedBackgroundView属性

问题:
那么,为什么A显示为单元格及其所有子视图的良好背景,而B中的UIImageView工作正常,但B中的UIView根本不显示,但我改变了它?谢谢

这是我找到的我的箱子。当我记录UIView背景色的RGB和alpha时,我发现在选择单元格时,它们都被设置为0:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat red, green, blue, alpha;
    [viewE.backgroundColor getRed:&red green:&green blue:&blue alpha:&alpha];
    NSLog(@"Selected: Red=%f, Green=%f, Blue=%f, alpha=%f", red, green, blue, alpha);
}

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    CGFloat red, green, blue, alpha;
    [viewE.backgroundColor getRed:&red green:&green blue:&blue alpha:&alpha];
    NSLog(@"Deslected: Red=%f, Green=%f, Blue=%f, alpha=%f", red, green, blue, alpha);
}
最初,不选择任何内容。点击表格中的一行,日志显示:

Selected: Red=0.000000, Blue=0.000000, Green=0.000000, alpha=0.000000
并且我的子视图不会出现(注意Alpha=0)。有趣的是,当我登录viewE.alpha时,它显示为1

再次点击该行以取消选择:

Deselected: Red=0.667000, Blue=0.776000, Green=0.220000, alpha=1.000000
这就是我所期望的

我的表格单元格是自定义UITableViewCell。因此,在我的自定义UITableViewCell类中,我添加了以下代码:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    UIColor *saveColor = self.viewE.backgroundColor;
    [super setSelected:selected animated:animated];
    if (selected)
        self.viewE.backgroundColor = saveColor;
}
现在,当选定单元时,将显示子视图视图


这里的代码似乎是在补偿一个本来不应该存在的条件,但它是有效的

我有一个确切的问题。你找到解决办法了吗?