【问题标题】:UITableViewCell textLabel color not changingUITableViewCell textLabel 颜色不变
【发布时间】:2011-09-26 18:04:15
【问题描述】:

我有一个 UITableView,作为 cellForRowAtIndexPath 方法,我正在更改单元格的一些属性(字体、大小等)。现在,除了更改 textLabel 的颜色之外,下面列出的所有分配都可以正常工作。我不明白为什么只有那个特定的颜色属性不会改变。我到处寻找我能想到的地方,以找出为什么它不起作用并且我被卡住了。有任何想法吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *kLocationAttributeCellID = @"bAttributeCellID";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kLocationAttributeCellID];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:kLocationAttributeCellID] autorelease];

        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0];
        cell.detailTextLabel.numberOfLines = 0;
        cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.userInteractionEnabled = NO;
        cell.textLabel.font = [UIFont fontWithName:@"Courier" size:18.0];
        cell.textLabel.textColor = [UIColor redColor]; // this never takes effect...
    }

    cell.textLabel.text = @"Test Label";
    cell.detailTextLabel.text = @"Test Details";
    return cell;
}

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    因为这样:

    cell.userInteractionEnabled = NO;
    

    如果您不希望您的单元格是可选的,请尝试使用此选项:

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    

    【讨论】:

    • 哦哇...什么废话。我想知道为什么这会对颜色产生影响。我已经尝试解决这个问题 3 天了。谢谢!!!
    • 2019 年,我仍然有同样的问题。删除 userInteractionEnabled = false 解决了问题:(
    猜你喜欢
    • 2010-11-12
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-16
    相关资源
    最近更新 更多