2

我有一个要在 UITableViewController 内编辑的 UITableView。这段代码来自我调用来编辑 tableView 的方法。

    [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: path] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject: path] withRowAnimation:UITableViewRowAnimationNone];

    NSMutableArray *things = [[self.fetchedResultsController fetchedObjects] mutableCopy];

    self.storedCell = [things objectAtIndex: path.row];

    [things removeObjectAtIndex: path.row];

    for ( int i = 0; i < [things count]; i++) {
        Task *mo = (Task *)[things objectAtIndex: i];
        [mo setValue:[NSNumber numberWithInt: i] forKey:@"displayOrder"];
    }
    [things release]; things = nil;
    self.newPath = path;

    [self.managedObjectContext save: nil]; 
    [self.tableView endUpdates];

这是抛出的错误:

    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempt to create two animations for cell'

关于我做错了什么的任何想法?

4

1 回答 1

3

如果您想要这样做,而不是删除然后插入同一行,只需重新加载它:

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:path] withRowAnimation:UITableViewRowAnimationNone];

但是,看起来您应该只是删除该行,因此您可能应该只删除该insertRowsAtIndexPaths行。(当然,您没有发布所有代码,所以我不确定......)

于 2012-04-07T02:52:17.883 回答