はい、同様の質問のタイトルでスタックオーバーフローに関する質問が非常に多くあります。私はそれらをすべて読みましたが、私の問題がそれらに相当することは決してありません。今私の問題は、セクション0のヘッダービューをクリックして3行を持つテーブルセクション0を更新し、セクション0から3行すべてを削除するために同じヘッダーをクリックすると、これでうまくいきます。しかし、(セクション 0 を 3 行で更新) を開いてから、別のヘッダー セクション (0 番目のセクションの後に開きたい別のセクション) をクリックすると、アプリケーションがクラッシュしました。つまり、他のセクションをクリックすると、他のセクションが開き、前に開いていたセクションが閉じなければならないということです。セクションと行の挿入と削除のコードを参照してください。
-(void)sectionHeaderView:(TableHeaderView*)sectionHeaderView sectionOpened:(NSInteger)section{
self.sectionOpen = YES;
//Create an array containing data of rows and section which to be inserted in tableView.
NSMutableArray *dataInsertArray = [NSMutableArray arrayWithArray:[self.tableDataSourceDictionary objectForKey: [self.sortedKeys objectAtIndex:section]]];
NSInteger countOfRowsToInsert = [dataInsertArray count];
NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < countOfRowsToInsert; i++) {
[indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]];
}
[self.tableContents setObject:dataInsertArray forKey:[self.sortedKeys objectAtIndex:section]];
//Create an array containing data of rows and section which to be delete from tableView.
NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
NSInteger previousOpenSectionIndex = self.openSectionIndex;
if (previousOpenSectionIndex != NSNotFound ) {
self.sectionOpen = NO;
[previousTableHeader toggleOpenWithUserAction:NO];
NSInteger countOfRowsToDelete = [[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]] count];
for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenSectionIndex]];
}
[self.tableContents removeObjectForKey:[self.sortedKeys objectAtIndex:previousOpenSectionIndex]];
}
// Apply the updates.
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
self.openSectionIndex = section;
self.previousTableHeader = sectionHeaderView;
}
そして私のデータソースメソッドは
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
NSInteger numberOfSection = [self.sortedKeys count];
return numberOfSection;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *listData =[self.tableContents objectForKey: [self.sortedKeys objectAtIndex:section]];
NSInteger numberOfRows = [listData count];
return numberOfRows;
}
私のクラッシュ レポート、 [UITableView _endCellAnimationsWithContext:] でのアサーションの失敗、/SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:1070 2013-02-18 11:44:49.343 ManageId[1029:c07] キャッチされない例外によるアプリの終了'NSInternalInconsistencyException'、理由: '無効な更新: セクション 0 の行数が無効です。更新後の既存のセクションに含まれる行数 (0) は、更新前にそのセクションに含まれる行数 (3 )、そのセクションから挿入または削除された行数 (挿入 0、削除 1) のプラスまたはマイナス、およびそのセクションに移動またはセクションから移動された行の数 (0 移動、0 移動) をプラスまたはマイナスします。
単純に、2 つのセクションに 3 ~ 3 行が含まれていると仮定すると、ファイルは機能しますが、2 つのセクションに 3 ~ 2 行が含まれていると、クラッシュします。これらのセクションの行数が矛盾しているセクションのヘッダーの更新をクリックして、2 つのセクションを切り替えたいと思います。
よりも