3

UITableView から行を削除しようとすると、このエラーが発生することがあります。

-[UITableView _endCellAnimationsWithContext:] でのアサーションの失敗

また、問題なく行を削除する場合もあります。

これが私のコードです:

- (void) tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
 forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
     [[self displayedObjects] removeObjectAtIndex:[indexPath row]];


     // Animate deletion
     NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
     [[self tableView] deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];

    }
}
4

2 に答える 2

4

編集モードに入ると、 numberOfRowsInSectionが間違った整数を返すことがあるようです。

于 2012-03-14T07:40:12.870 に答える
1

よくわかりません..しかし、これを試してください(一度私のために働いた)

最初に UITableView の削除をアニメーション化してから、配列からオブジェクトを削除します。

if (editingStyle == UITableViewCellEditingStyleDelete)
    {
     // Animate deletion
     NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
     [[self tableView] deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];

    [[self displayedObjects] removeObjectAtIndex:[indexPath row]];

    }
于 2012-03-14T07:35:48.780 に答える