2010-08-30 5 views
2

Je souhaite définir l'image d'arrière-plan pour la cellule. J'ai déjà défini les images d'arrière-plan pour les cellules dans la vue de tableau. Mais je veux définir les deux images pour les images d'arrière-plan dans la cellule de vue de la table. Je veux mettre les cellules alternatives pour l'arrière-plan,Comment définir l'image d'arrière-plan dans la cellule de vue de table de l'iPhone

Comme,

Image1- Cell 1, Cell 3, Cell 5, Etc., 

    Imgae-2- Cell 2, Cell 4,Cell 6, Etc., 

S'il vous plaît me guider et me donner quelques liens d'échantillons.

Merci!

Répondre

8

Vous pouvez configurer deux cellules différentes pour même/lignes inégales comme ci-dessous

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    static NSString *CellIdentifierEvenRows = @"MyCellEven"; 
    static NSString *CellIdentifierUnevenRows = @"MyCellUneven"; 
    UITableViewCell *cell; 

    if (indexPath.row % 2) { 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierUnevenRows]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
              reuseIdentifier:CellIdentifierUnevenRows] autorelease]; 
      cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"uneven.png"] autorelease]; 
     } 
    } else { 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierEvenRows]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
              reuseIdentifier:CellIdentifierEvenRows] autorelease]; 
      cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"even.png"] autorelease]; 
     } 
    } 

    return cell; 
} 

(non testé) mais

+0

de cell.backgroundView sera 'cell.backgroundView = [[[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "even.png"]] autorelease]; ' –

Questions connexes