Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ws47

macrumors newbie
Original poster
Jun 30, 2009
7
0
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:
Code:
- (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]) {
        abort();
    }
}

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?
 
Remove the reloadData and add in a begin/end updates block for fully animated goodness

Code:
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
 
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.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.