错误: The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:1070
libc++abi.dylib: handler threw exception
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [_arrKeys count];// _arrKeys中存放分组
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSString* _date = [_arrKeys objectAtIndex:section];
NSArray* _notifications = [_dictData objectForKey:_date];// _dictData存放数据
return [_notifications count];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self refreshData];// 刷新_arrKeys和_dictData中的数据
int newCount=0;
if (indexPath.section<[_arrKeys count]) {
NSString *_date = [_arrKeys objectAtIndex:indexPath.section];
NSArray* _notifications = [_dictData objectForKey:_date];// _dictData存放数据
newCount= [_notifications count];
}
[tableView beginUpdates];
if (newCount<=0) {
[tableView deleteSections:[NSIndexSetindexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationLeft];
}
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationLeft];
[tableView endUpdates];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// 修改时
}
}