2010-10-21 20 views
8

Come posso eliminare una riga UITableView sullo scorrimento? So che la domanda è stata fatta, ma ottengo solo errori. Ecco il codice:Scorri per eliminare 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];  
    } 
} 

Ma non succede nulla. Apprezzerei se scrivessi il codice.

risposta

7

ricaricare la tabella dopo aver rimosso la riga.

[tableView reloadData]; 
+0

OMG! E 'stato così facile! Grazie mille! – KillaIce

+1

:) Perché non accetti la risposta? –

+0

Posso farlo in 3 minuti :( – KillaIce

44

Meglio è solo quello di eliminare la riga selezionata, non caricare tutto il tavolo:

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

Questo è meglio :) –

+0

la riga sopra mi ha dato un errore, quindi questo (più o meno lo stesso) funziona bene. '[myTable deleteRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationFade];' – alexdd55

Problemi correlati