UITableViewCell textColor不会随userInteractionEnabled = NO而改变

Osc*_*mez 4 iphone uitableview uilabel uicolor

我试图简单地改变我UILabel使用textColor属性的颜色,当禁用userInteraction时它将无法工作,这没有任何意义,文档中没有提到任何内容.但是,如果我删除该行颜色确实发生了变化,那就是正在发生的事情,但我不想要用户交互.

UITableViewCellStyleValue1
Run Code Online (Sandbox Code Playgroud)

单元格样式,单元格左侧带有标签,左对齐和黑色文本 ; 在右侧是一个标签,蓝色文字较小,右对齐."设置"应用程序使用此样式的单元格.适用于iOS 3.0及更高版本.

两个标签都是灰色,并且它们不会改变颜色.这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }

    //If I remove this line the color changes
    cell.userInteractionEnabled = NO;

    UIColor *blackColor = [UIColor blackColor];

    UILabel *mainLabel = cell.textLabel;
    UILabel *detailTextLabel = cell.detailTextLabel;
    mainLabel.backgroundColor = blackColor;
    detailTextLabel.backgroundColor = blackColor;

    //Trying to change color here but no effect
    mainLabel.textColor = [UIColor redColor];
    detailTextLabel.textColor = [UIColor whiteColor];

    UIView *backView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];
    backView.backgroundColor = blackColor;
    cell.backgroundView = backView;

    mainLabel.text = @"Some text";

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

编辑:我刚刚意识到,它与userInteractionEnabled = NO删除文本颜色更改有关,但我不希望用户交互,我怎么能关闭它但也改变颜色?,而不必创建我自己的UILabels并添加它们这个contentView.

Osc*_*mez 10

好的,我知道如何解决这个问题,但它根本没有任何意义,问题是这一行:

cell.userInteractionEnabled = NO;
Run Code Online (Sandbox Code Playgroud)

如果删除了textColor更改,奇怪的是,如果我在更改textColor颜色更改后更改用户交互!

这是一个错误吗?我希望这个答案有助于任何人试图解决这个问题,因为它根本没有任何意义,并且没有关于此的文档.