1

NSMutableArrayオブジェクトを表示するtableViewがあり、現在tableView:commitEditingStyle:forRowAtIndexPath:メソッドを実装しようとしています。この行をコメントアウトすると[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];、UI の更新以外はすべて正常に機能します。

これは私のメソッドの実装です:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.modelClass removeObjectAtRow:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}

これは私が得るエラーです:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2280.1/UITableView.m:1060

他の質問には、 を に置き換える必要があることを示唆する回答がありました@[indexPath][NSArray arrayWithObject:indexPath]、同じエラーが発生します。

4

2 に答える 2

3

問題はメソッドにある可能性があります。numberOfRowsInSectionしたがって、問題を解決するには:

関数commitEditingStyleでは、配列、データベースなどからデータを削除します。現在の行数を減らします。

[tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];

そして、あなたの問題は解決されます!!!

于 2012-07-02T05:12:30.620 に答える
2

これは、行の削除後UITableViewにデータソース メソッドnumberOfRowsInSectionに再び入るために発生します。にある正しい行数が返されることを確認してself.modelClass.countください numberOfRowsInSection

于 2012-07-02T05:12:24.553 に答える