更改所选UITableViewCell子类中的元素

我为我的应用程序实现了一个自定义UITableViewCell,并创建了一个自定义背景视图和selectedbackgroundview,两者都很好用。 但是,我在单元格上有几个其他图像和uilabels,我想要更改它的颜色。 我已经覆盖了以下方法,并且在选择单元格时它会正确记录,但它不会更改图像或文本颜色。

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; if (selected) { NSLog(@"setSelected:YES"); separatorImage.image = [UIImage imageNamed:@"SeparatorSelected"]; titleLabel.textColor = [UIColor whiteColor]; } else { NSLog(@"setSelected:NO"); separatorImage.image = [UIImage imageNamed:@"Separator"]; titleLabel.textColor = [UIColor grayColor]; } } 

任何想法我做错了什么?

更新

 separatorImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Separator"]]]; [separatorImage setFrame:CGRectMake(99, 4, 5, 71)]; separatorImage.backgroundColor = [UIColor clearColor]; [self.contentView addSubview:separatorImage]; titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(111, 4, 188, 26)]; titleLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:21.0]; titleLabel.backgroundColor = [UIColor clearColor]; [self.contentView addSubview:titleLabel]; 

我有一种预感,即在方法开头发送-setSelected:animated: to super会阻止对单元格的更改。 尝试将调用移动到super到方法的末尾。 您还应该覆盖-setHighlighted:animated:或者您的选择似乎会滞后。