2010-08-29 8 views
1

J'ai un UITableView sectionné en utilisant des dictionnaires adaptant le code d'un tutoriel (je n'ai pas de lien sur moi pour le moment mais je peux le déterrer si vous en avez vraiment besoin).UITableView Sectionnement Ligne Question

Quoi qu'il en soit, je suis en train de faire supprimer un élément de la liste lorsque je reçois cette erreur (avertissement: sa longue)

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted). 

Je me Kind des informations sur le nombre de lignes, mais je m écrou sûr comment résoudre ce problème.

Si vous voulez voir les informations de débogage je l'ai coller mis en cellule parce que son si longtemps: http://pastebin.com/0difSEnM

Voici mon code:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)index { 
NSDictionary *dictionary = [data objectAtIndex:index.section]; 
NSMutableArray *array = [NSMutableArray arrayWithArray:[dictionary objectForKey:@"My Wishlists"]]; 
NSString *selectedWishlist = [array objectAtIndex:index.row]; 
//now remove the item 
[array removeObjectAtIndex:index.row]; 
[data removeObjectAtIndex:index.section]; 
NSDictionary *newdictionary = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:array] forKey:@"My Wishlists"]; 
[data insertObject:newdictionary atIndex:0]; 
// [data addObject:newdictionary]; 
[mainTableView reloadData]; // tried without and with this, no difference 
[mainTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationTop]; 
} 

Merci! Stewart Christian

Répondre

1

On dirait que ceci est votre problème:

[data insertObject:newdictionary atIndex:0]; 

De la documentation pour insertObject:atIndex: de NSMutableArray:

Discussion Si index est déjà occupé, les objets à l'index et sont décalés en ajoutant 1 à leurs indices pour faire de la place.

Essayez à la place d'utiliser replaceObjectAtIndex:withObject:.

Questions connexes