1 votes

Comment mettre en évidence une UITableViewCell ?

J'aimerais beaucoup mettre temporairement en évidence une UITableViewCell pour attirer l'attention sur le fait que les données qu'elle contient ont changé.

il existe une méthode UITableViewCell : -setHighlighted :(BOOL) animated :(BOOL) mais je n'arrive pas à lui faire faire quoi que ce soit ?

Voici la partie pertinente du contrôleur de vue :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  UITableViewCell *cell;
  switch (indexPath.section) {
    case 0: {
     if (indexPath.row == 0) {
    cell = [[UITableViewCell alloc ] initWithStyle:UITableViewCellStyleDefault 
                                   reuseIdentifier:@"currentLoc"];
    cell.accessoryType = UITableViewCellAccessoryNone;
      cell.textLabel.text = @"This is the special cell";
    }
    [cell setHighlighted:YES animated:YES];
    [cell setHighlighted:NO animated:YES];

    //[cell setNeedsDisplay];

  } else {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier:@"setLocAutomatically"];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.textLabel.text = @"Foo";

  }
} break;
case 1: {
  cell = [[UITableViewCell alloc ] initWithStyle:UITableViewCellStyleDefault
                                 reuseIdentifier:@"selectCity"];
  cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  if (indexPath.row == 0) {
    cell.textLabel.text = @"Select a Bar";
  } else {
    cell.textLabel.text = @"Select a Baz";
  }
} break;
  }
  [cell autorelease];
  return cell;
}

Voir la [cell setHighlight...] ci-dessus pour ma tentative.

À ma grande frustration, la cellule ne se met pas en évidence et je n'ai pas trouvé le moyen de la faire fonctionner.

Merci,

Carl C-M

0voto

intropedro Points 1206

Essayez ça :

[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];

0voto

Pinglebon Points 13
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
      if (//tell if cell is marked) {
            [cell setBackgroundColor:[UIColor colorWithRed:158.0/255.0 green:28.0/255.0 blue:36.0/255.0 alpha:1.0]];
            [[cell textLabel] setTextColor:[UIColor whiteColor]];
            if ([cell detailTextLabel]) {
                  [[cell detailTextLabel] setTextColor:[UIColor whiteColor]];
            }
      }
      else
      {
            [cell setBackgroundColor:[UIColor whiteColor]];
            [[cell textLabel] setTextColor:[UIColor blackColor]];
            if ([cell detailTextLabel]) {
                  [[cell detailTextLabel] setTextColor:[UIColor blackColor]];
            }
      }
}

utilisez ceci dans le délégué de l'uitableview, puis lorsque vous voulez mettre en évidence la cellule, marquez la cellule et appelez reloadData sur le tableau.

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X