2010-10-21 4 views
8

Comment puis-je supprimer une ligne UITableView lors d'un balayage? Je sais que la question a été posée, mais je n'ai que des erreurs. Voici le code:Glisser pour supprimer UITableView

-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath { 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
    forRowAtIndexPath:(NSIndexPath *)indexPath { 
    // If row is deleted, remove it from the list. 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     NSInteger row = [indexPath row]; 
     [tableDataSource removeObjectAtIndex:row];  
    } 
} 

Mais rien ne se passe. J'apprécierais si vous écrivez le code.

Répondre

7

Recharger la table après avoir retiré la ligne.

[tableView reloadData]; 
+0

OMG! Et c'était aussi simple que ça! Merci beaucoup! – KillaIce

+1

:) Pourquoi ne pas accepter la réponse alors? –

+0

Je peux le faire en 3 minutes :( – KillaIce

44

Mieux vaut simplement supprimer la ligne sélectionnée, pas recharger tout le tableau:

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
+0

Celui-ci est meilleur :) –

+0

la ligne ci-dessus m'a donné une erreur, donc cela (à peu près la même chose) fonctionne bien. '[myTable deleteRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationFade];' – alexdd55

Questions connexes