Reputation: 105
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. I would appreciate if you write code.
Upvotes: 8
Views: 8884
Reputation: 7427
Better is just to delete the selected row, not reload all the table:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
Upvotes: 45