Reload table view data after deleting row

Discussion in 'iOS Programming' started by ws47, Mar 24, 2011.

  1. ws47 macrumors newbie

    Jun 30, 2009
    I have a table view where some information is displayed in the subtitle of each cell. After a cell is deleted, this information needs to be recalculated. Here is my commitEditingStyle method:
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            // Delete the row from the data source
            NSManagedObject *objectToDelete = [peopleArray objectAtIndex:indexPath.row];
            [managedObjectContext deleteObject:objectToDelete];
            [peopleArray removeObjectAtIndex:indexPath.row];
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [tableView reloadData];
        NSError *error = nil;
        if (![managedObjectContext save:&error]) {
    My problem is that calling [tableView reloadData] interrupts the nice fading animation for deleting a row, and instead the delete is not animated. Is there any way to reload the data without interrupting the animation?
  2. dantastic macrumors 6502a


    Jan 21, 2011
    Remove the reloadData and add in a begin/end updates block for fully animated goodness

    [tableView beginUpdates];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    [tableView endUpdates];
  3. ws47, Mar 24, 2011
    Last edited: Mar 24, 2011

    ws47 thread starter macrumors newbie

    Jun 30, 2009
    That didn't work. Well the animation worked but the subtitles display the wrong information. What needs to happen is that when the row gets deleted, the text in the subtitles of each row needs to be updated to reflect the change. So I think I need some sort of call to reload the data, I just need to have it animated. The problem is the call to reload the data stops the animation. I'm currently using an NSTimer set for 0.3 seconds to call reloaddata, but it seems like there should be a better solution.

Share This Page