2010-01-27 4 views
1

J'ai lu des messages ici sur SO sur le striping des cellules d'UITableView, mais je n'ai pas réussi à trouver les détails. Mon code est:Lignes de striping d'un UITableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Setup code omitted 

    cell.textLabel.text = @"Blah Blah"; 
    cell.detailTextLabel.text = @"Blah blah blah"; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    if ([indexPath row] % 2 == 1) { 
     cell.contentView.backgroundColor  = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; 
     cell.textLabel.backgroundColor  = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.0]; 
     cell.detailTextLabel.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; 
     cell.accessoryView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; 
    } 
    return cell; 
} 

Et mon résultat est:

http://img2.pict.com/18/df/b9/2661271/0/screenshot20100127at3.png

Toutes les idées pourquoi cela se passe? Merci!

Répondre

4

Ces cellules se réutilisés, vous devez le remettre à la normale dans le cas de [indexpath row] % 2 == 0

+0

Est-ce que, mais il n'a pas résolu quoi que ce soit. Toujours obtenir le même effet vu ci-dessus. –

2
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
     [cell setBackgroundColor: indexPath.row % 2 == 0 ? color1 : color2]; 

}

Questions connexes