UITableViewCell textColor将不会随着userInteractionEnabled = NO更改 [英] UITableViewCell textColor will not change with userInteractionEnabled = NO

查看:92
本文介绍了UITableViewCell textColor将不会随着userInteractionEnabled = NO更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用textColor属性简单地更改UILabel的颜色,并且在禁用userInteraction时将不起作用,这没有任何意义,文档中根本没有提及.但是,如果我删除该行,就会发生这种情况,颜色会发生变化,但是我不希望用户进行交互.

I am trying to simply change the color of my UILabel using the textColor property and it will not work when userInteraction is disabled, this does not make any sense, there is nothing in the documentation that mentions that at all. But that is what is happening if I remove that line the color does change, but I do not want user interaction.

UITableViewCellStyleValue1

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

A style for a cell with a label on the left side of the cell with left-aligned and black text; on the right side is a label that has smaller blue text and is right-aligned. The Settings application uses cells in this style. Available in iOS 3.0 and later.

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

Both labels are in gray color, and they will not change color. Here is my code:

- (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;
}

我刚刚意识到,它与userInteractionEnabled = NO有关,当删除了文本颜色更改时,但是我不希望用户交互,如何关闭它又更改颜色?而无需创建我自己的UILabels并将它们添加到contentView.

I just realized, it is related to the userInteractionEnabled = NO, when removed the text Color changes, but I do not want user interaction, how can i turn that off but also change the color?, without having to create my own UILabels and adding them to the contentView.

推荐答案

好吧,我知道如何解决此问题,但它根本没有任何意义,问题在于此行:

Ok I know how to fix this but it does NOT make any sense at all, the problem is this line:

cell.userInteractionEnabled = NO;

如果删除了textColor更改,那么奇怪的是,如果我在更改textColor之后最后更改了用户交互,则颜色也会更改!

If removed the textColor changes, the odd thing is that if i change the user interaction at the end after changing the textColor the color changes!

这是一个错误吗?我希望这个答案能帮助任何试图弄清楚这一点的人,因为这根本没有任何意义,并且没有关于此的文档.

Is this a bug?. I hope this answer helps anyone trying to figure this out as it does not make any sense at all, and there is no documentation about this.

这篇关于UITableViewCell textColor将不会随着userInteractionEnabled = NO更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆