私は自分のアプリケーション用にカスタムUITableViewCellを実装しており、カスタムバックグラウンドビューとselectedbackgroundviewを作成しました。しかし、私は色が選択されたときに色を変更したい、セルにいくつかの他の画像とユーラベルを持っています。次のメソッドを上書きしました。セルが選択されても、イメージやテキストの色は変更されません。選択されたUITableViewCellサブクラスのエレメントを変更する
- (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];
あなたのメソッドの最後に '[self setNeedsDisplay];'を呼び出そうとしましたか? –
ええ、私はそれを試みましたが、何もしなかったので削除しました。 – xizor
'separatorImage'と' titleLabel'はどのように定義されていますか? – jrtc27