nit*_*hin 2 iphone objective-c uitableview ios
使用commitEditingStyle 从Uitableview中删除行时,我的应用程序崩溃时出现此错误.
断言失败 - [UITableView _endCellAnimationsWithContext:],/ SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:1046.由于未捕获的异常导致应用程序NSInternalInconsistencyException',原因:'无效更新:第0节中的行数无效.更新后的现有部分中包含的行数(2)必须等于更新前的该部分中包含的行数(1),加上或减去从该部分插入或删除的行数(0插入,1删除)并加上或减去移入或移出该部分的行数(0移入,0移出).
这是我的代码:
- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete) {
order *OrderObj= [appDelegate.orderArray objectAtIndex:[indexPath row]];
[appDelegate removeitem:OrderObj];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
} }
Run Code Online (Sandbox Code Playgroud)
尝试更改这些行:
order *OrderObj= [appDelegate.orderArray objectAtIndex:[indexPath row]];
[appDelegate removeitem:OrderObj];
Run Code Online (Sandbox Code Playgroud)
至:
[appDelegate.orderArray removeObjectAtIndex:[indexPath row]]; // assuming orderArray is NSMutableArray
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3759 次 |
最近记录: |