Je sais que ça va être un de ces moments de tête-claquant.UITableView didSelectRowAtIndexPath a seulement déclenché quelques fois
J'ai une UITableView à partir de laquelle j'ai besoin de supprimer des cellules. Le problème est que didSelectRowAtIndexPath n'est appelé que si je tape d'abord la ligne, puis balayez pour afficher le bouton de suppression. Si je balaye la ligne sans tapoter explicitement la ligne, j'obtiens une erreur EXC_BAD_ACCESS. J'ai mis un NSLog dans didSelectRowAtIndexPath et peux voir le tableau d'indexPath quand je tape la cellule, mais rien si je fais simplement glisser sans cliquer.
J'ai fait ma part de recherche et je suis sûr à 99% que mon délégué est correctement connecté (habituellement le problème # 1) et n'a pas tapé didDeselectRowAtIndexPath (habituellement problème # 2). J'ai aussi dans mon fichier .h (problème # 3).
Merci d'avance.
EDIT:
Je l'ai dit: Si je glisser la ligne sans taper explicitement la ligne, je reçois une erreur de EXC_BAD_ACCESS quand je tape sur le bouton Supprimer. Si je tape sur la cellule, puis glisser, je peux appuyer sur Supprimer et il supprime comme prévu.
EDIT:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[bandList sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
NSDictionary *dict = [bandList objectAtIndex:indexPath.row];
cell.textLabel.text = [dict objectForKey:@"name"];
return cell;
}
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
NSLog(@"IndexPath: %@", [indexPath description]);
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
NSDictionary *selectedBand = [bandList objectAtIndex:indexPath.row];
NSString *selectedBandId = [selectedBand objectForKey:@"id"];
[self deleteMyBand:selectedBandId];
bandList = [self getSavedBands];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
Veuillez publier votre code pour didSelectRowAtIndexPath, les méthodes de délégation de suppression et cellForRowAtIndexPath. –
Merci pour votre aide, @XcodeDev. J'ai mis à jour le message original. – voodoobilly
Vous triez votre 'bandList' à chaque fois que tableView vous demande une nouvelle cellule. 'cellForRowAtIndexPath' n'est pas le meilleur endroit pour préparer vos données. De plus, si 'bandList' change avec le temps, votre tableView deviendra incohérent. – kelin