Iphone 从UItableview删除行时崩溃

Iphone 从UItableview删除行时崩溃,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,使用CommittedItingStyle从Uitableview中删除行时,我的应用程序会因此错误崩溃 -[UITableView\u endCellAnimationsWithContext:]中的断言失败, /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:1046.终止 应用程序由于未捕获异常NSInternalInconsistencyException', 原因:“无效更新:节0中的行数无效。这个 更新后现有节中包含的行数(2) 必须

使用CommittedItingStyle从Uitableview中删除行时,我的应用程序会因此错误崩溃

-[UITableView\u 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];
    }   }

更新后,您的
表视图:numberofrowsinssection:
返回的值不正确。检查删除前和删除后返回的值。它必须减少1。

尝试更改以下行:

order *OrderObj= [appDelegate.orderArray objectAtIndex:[indexPath row]];
[appDelegate removeitem:OrderObj];
致:


谢谢回复..您的回答将从tableview中删除项目,但我也需要删除项目数据库..@nithin。然后只需将我的行添加到您的行中,而不删除:)。我猜您从数据库中删除了对象,但出现崩溃是因为orderArray中的对象计数不正确
[appDelegate.orderArray removeObjectAtIndex:[indexPath row]]; // assuming orderArray is NSMutableArray