开发者

UITableView "swipe to delete" function freezes

I can't figure out why my tableView isn't updating after I tap the delete button.

Once I click it, the table view "freezes". If I click another row, so that the tableview goes to another level of the hierarchy and click back, I can see that the item has been deleted and everything works fine.

Here is my code:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    //[tableView beginUpdates];    
    if (editingStyle == UITab开发者_Python百科leViewCellEditingStyleDelete) 
    {
        // Do whatever data deletion you need to do...
        [tableView beginUpdates];
        NSManagedObject *obj = (NSManagedObject *)[entityArray objectAtIndex:indexPath.row];        
        [managedObjectContext deleteObject:obj];
        NSError *error;
        [managedObjectContext save:&error];

        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:YES];

         [self viewWillAppear:YES];

    }
    //[tableView endUpdates];
}

Any input on this problem would be appreciated.

Thanks.


Found same issue and stumbled upon this thread. But the reason for the tableview freeze issue was different in our case.

For the sake of posterity:

The UITableViewCell which goes into Edit mode to display the "insert" or "delete" buttons should never have its userInteractionEnabled property set to "NO".

By correcting this, the same tableview freezing issue was fixed for us.


I can't see a call to [tableView endUpdates] matching the [tableView beginUpdates] that is at start of the if.

Could it be for this reason that your table freezes?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜