views:

37

answers:

2

How can I delete a UITableView row on swipe? I know the question has been asked, but I get only errors. Here's the code:

-(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];      
    }
}

But nothing happens. Help me, please. I would appreciate if you write code.

Thanks in advance!

A: 

reload table after removing the row.

[tableView reloadData];
ahmet emrah
OMG! And that was that easy! Thank you so much!
KillaIce
:) Why dont you accept the answer then?
ahmet emrah
I can do it in 3 minutes :(
KillaIce
+4  A: 

Better is just to delete the selected row, not reload all the table:

 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
Benoît
This one's better:)
ahmet emrah