Couleur UITableView cell textLabel
J'ai une question simple, avec UITableViewCell
.
Ce que je veux, c'est changer la couleur du texte d'une cellule sélectionnée.
Dans mon cellForRowAtIndexPath
méthode, j'ai mis:
cell.textLabel.textColor = [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.highlightedTextColor = [UIColor orangeColor];
Si le selectionStyle
est UITableViewCellSelectionStyleNone
highlightedTextColor
ne changera pas.
J'ai donc utiliser ces deux méthodes pour définir la couleur du texte:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor orangeColor];
return indexPath;
}
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor whiteColor];
return indexPath;
}
Cela fonctionne, mais lorsque vous faites défiler la tableview, les changements de couleur au dos.
source d'informationauteur Guru
Vous devez vous connecter pour publier un commentaire.
Ont la solution
par la définition de la couleur dans si (cellule == nil) vérifier
et
Grâce
Tout ce que vous avez à faire est de
à l'intérieur si(cellule == nil)
qui fonctionnera très bien.
définir une :
int m_selectedCell;
modifier
et
juste ajouter
dans
c'est tout !