2011-12-08 6 views
1

私は自分のアプリケーション用にカスタム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]; 
+1

あなたのメソッドの最後に '[self setNeedsDisplay];'を呼び出そうとしましたか? –

+0

ええ、私はそれを試みましたが、何もしなかったので削除しました。 – xizor

+0

'separatorImage'と' titleLabel'はどのように定義されていますか? – jrtc27

答えて

5

私は、メソッドの開始時にsuper-setSelected:animated:を送信すると、あなたの携帯への変更を防止していることを予感しています。方法の最後までsuperに移動してみてください。また、-setHighlighted:animated:を上書きする必要があります。そうしないと選択が遅れて表示されます。

+0

Hunch Correct !!! – xizor

+0

私はスーパーコールを最後まで移動する必要があることが判明しました。ご協力いただきありがとうございます。 – xizor

+0

>>>>>> BOSS MOVE <<<<< – user

関連する問題