2011-11-04 4 views
0

Je veux montrer une image si chaque ligne commence par un certain caractère, disons "&" dans l'exemple ci-dessous. Le code ci-dessous ne semble fonctionner que si la première ligne ne commence pas par '&'. Si la première ligne a '&' toutes les lignes auront l'image. Qu'est-ce qui ne va pas?Evaluer chaque ligne de UITableView séparément iPhone

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    if ([[[array objectAtIndex:(indexPath.row)] substringToIndex:1] isEqualToString:@"&"]) 
     { 
      cell.textLabel.text = [array objectAtIndex:(indexPath.row)]; 
      cell.detailTextLabel.text = [array objectAtIndex:(indexPath.row)+1]; 
      cell.imageView.image = [UIImage imageNamed:@"picture.png"]; 
      return cell; 
     } 
     else 
     { 
      cell.textLabel.text = [array objectAtIndex:(indexPath.row)]; 
      cell.detailTextLabel.text = [array objectAtIndex:(indexPath.row)+1]; 
      return cell; 
     } 
    } 

Répondre

0

Depuis la première cell peut être réutilisé plus tard, vous devez « réinitialiser » son état à chaque appel de cellForRowAtIndexPath. Essayez d'ajouter cell.imageView.image = nil après cell.detailTextLabel.text dans le bloc else.

Questions connexes