0

I can delete some rows, but at some point, I cannot delete anymore. The first numbers of rows that I can delete is aleatory.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        //add code here for when you hit delete
        [detailProductArray removeObjectAtIndex:indexPath.row];
        [detailTableView reloadData];
    }
}

Some of you have an idea ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ΩlostA
  • 2,501
  • 5
  • 27
  • 63

2 Answers2

2

I would like to direct you here for a complete answer for removing and adding rows. Add/Delete UITableViewCell with animation?

UITableviewView's can have rows added and removed in an animated fashion using the following methods.

[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
Community
  • 1
  • 1
  • Thanks a lot, it is very instructive. – ΩlostA Dec 14 '15 at 16:54
  • I don't see what this has to do with the question. @Claudio - can you explain how this answer solved your question? – rmaddy Dec 14 '15 at 16:55
  • [tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade]; This is like your previous comment deleteRowsAtIndexPaths:withRowAnimation: and the insertIndexPaths: is completing the answer for eventually inserting rows. – ΩlostA Dec 14 '15 at 17:28
0

My final code :

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        //add code here for when you hit delete
        [detailProductArray removeObjectAtIndex:indexPath.row];
        [DetailTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }
}
ΩlostA
  • 2,501
  • 5
  • 27
  • 63