2011-09-26 11 views
8

Tengo un UITableView y como el método cellForRowAtIndexPath estoy cambiando algunos atributos de la celda (fuente, tamaño, etc.) Ahora todas las asignaciones enumeradas a continuación funcionan bien excepto cambiar el color de el textoLa etiqueta No puedo entender por qué solo ese atributo de color específico no cambiará. He buscado en todas partes donde puedo pensar para descubrir por qué no funciona y estoy atascado. ¿Algunas ideas?UITableViewCell textLabel color no cambia

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

Respuesta

9

Es debido a esto:

cell.userInteractionEnabled = NO; 

Si no desea que sus células sean seleccionables, trate de usar esto en su lugar:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 
+1

Oh wow ... lo que la basura . Me pregunto por qué eso tiene un efecto en el color. He estado tratando de resolver esto por 3 días como ahora. ¡¡¡Gracias!!! – gplocke

+0

¡Muchas gracias! Perder horas reflexionando sobre este ... – ewiinnnnn

Cuestiones relacionadas