简体   繁体   中英

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM