3

UITableView次のコードで更新しようとしています。

NSMutableIndexSet *sectionsToDelete = [NSMutableIndexSet indexSet];
NSMutableIndexSet *sectionsToInsert = [NSMutableIndexSet indexSet];
NSMutableIndexSet *sectionsToReload = [NSMutableIndexSet indexSet];

/* ... */

[[self tableView] beginUpdates];
if ([sectionsToReload count]) {
    DBGLogObject(sectionsToReload);
    [[self tableView] reloadSections:sectionsToReload withRowAnimation:animation];
}
if ([sectionsToDelete count]) {
    DBGLogObject(sectionsToDelete);
    [[self tableView] deleteSections:sectionsToDelete withRowAnimation:animation];
}
if ([sectionsToInsert count]) {
    DBGLogObject(sectionsToInsert);
    [[self tableView] insertSections:sectionsToInsert withRowAnimation:animation];
}
[[self tableView] endUpdates];

ログ:

sectionsToReload = <NSMutableIndexSet: 0x71b19f0>[number of indexes: 2 (in 1 ranges), indexes: (1-2)]
sectionsToInsert = <NSMutableIndexSet: 0x71ac570>[number of indexes: 3 (in 2 ranges), indexes: (0 3-4)]

sectionsToDelete(ログにないことに注意してください。)

問題は、削除がなくてもエラーが発生することです。

2012-10-04 19:21:16.769 Syntax[903:c07] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:826
2012-10-04 19:24:51.655 Syntax[903:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete section 2, but there are only 2 sections before the update'

何か案は?

4

3 に答える 3

3

実際、私はあなたのエラーを複製しました-この更新の前にデータに2つのセクションしかない場合(これはエラーメッセージによって示されます)、セクション1と2をリロードすることはできません。0と1を更新するつもりでしたか? ?リロードが発生すると、最初に古いデータを削除してから新しいデータを追加する必要があると思います。そのため、削除エラーメッセージが表示されます。

于 2012-10-06T02:58:19.083 に答える
0

データソースを変更する必要があります。行またはセクションを削除する場合は、tableView の行またはセクションの数を変更する必要があります

于 2013-11-25T09:28:01.797 に答える
0

「Clean Build Folder」を実行すると、期待どおりに機能するようになりました。理由がわかりません。

于 2012-10-06T19:55:54.033 に答える