Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell textLabel color not changing

I've got a UITableView and as the cellForRowAtIndexPath method I am changing some attributes of the cell (font, size, etc.) Now all of the assignments listed below work just fine except changing the color of the textLabel. I can't figure out why only that specific color attribute won't change. I've looked about everywhere I can think of to figure out why it isn't working and I'm stuck. Any ideas?

- (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;
}
like image 339
gplocke Avatar asked Sep 26 '11 18:09

gplocke


1 Answers

It's because of this:

cell.userInteractionEnabled = NO;

If you don't want your cells to be selectable, try using this instead:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
like image 112
hwaxxer Avatar answered Nov 04 '22 21:11

hwaxxer