UITableViewCell textLabel颜色不变

时间:2011-09-26 18:04:15

标签: ios uitableview

我有一个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;
}

1 个答案:

答案 0 :(得分:10)

正因为如此:

cell.userInteractionEnabled = NO;

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

cell.selectionStyle = UITableViewCellSelectionStyleNone;
相关问题