如何在突出显示的状态下更改UITableViewCell文本颜色?

She*_*lam 4 iphone cocoa-touch objective-c uitableview

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    if (selected) {
        companyLabel.textColor = [UIColor whiteColor];
        priceLabel.textColor = [UIColor whiteColor];
        changeLabel.textColor = [UIColor whiteColor];
        symbolLabel.textColor = [UIColor whiteColor];
    }
    else
    {
        companyLabel.textColor = [UIColor blackColor];
        priceLabel.textColor = [UIColor blackColor];
        symbolLabel.textColor = [UIColor blackColor];

        if([changeLabel.text doubleValue] < 0)
        {
           changeLabel.textColor = [UIColor colorWithRed:239.0/255.0 green:16.0/255.0 blue:52.0/255.0 alpha:1.0];
        }
        else if([changeLabel.text doubleValue] > 0)
        {
           changeLabel.textColor = [UIColor colorWithRed:77.0/255.0 green:161.0/255.0 blue:0.0 alpha:1.0];
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

直到下一个视图被推入导航堆栈之后,我的文本才会变为白色.

我希望它变成白色,即使用户点击+持有一个单元格.

kri*_*ris 17

UILabel■找一个highlightedTextColor属性.当像a这样的视图UITableViewCell进入其突出显示状态时,所有子视图(包括您的标签)都应自动更改为使用其突出显示的属性.如果它仍然不起作用,那么还有一个用于禁用该功能的字段,您可能需要检查该功能.