【问题标题】:problem while deleting the row of a grouped table删除分组表的行时出现问题
【发布时间】:2011-05-20 14:00:19
【问题描述】:

大家好

我正在使用以下代码删除 rgouped 表视图中的一行

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath {

    if(editingStyle == UITableViewCellEditingStyleDelete) {

        //Get the object to delete from the array.
        insertUpdateDelete *objInsertUpdateDelete = [appDelegate.arrObjects objectAtIndex:indexPath.row];
        [appDelegate DeleteRecord:objInsertUpdateDelete];

        //Delete the object from the table.
        [tableView1 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}


    }

但它在生产线上崩溃了

[tableView1 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

崩溃日志是:

2011-05-20 19:21:20.233 iICS[10744:207] * 断言失败 在 -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:995 2011-05-20 19:21:20.235 iICS[10744:207]

 *** Terminating app due to uncaught exception

'NSInternalInconsistencyException', 原因:'无效更新:无效 第 0 节中的行数。 包含在一个中的行数 更新后的现有部分 (3) 必须等于行数 载于该节之前 更新(3),加减数字 从中插入或删除的行数 部分(0 插入,1 删除)。'

有朋友可以帮帮我吗?提前谢谢

【问题讨论】:

    标签: iphone objective-c xcode4


    【解决方案1】:

    在调用deleteRowsAtIndexPaths: 之前,请确保您的数据源反映了您所做的更改。我看到您正在调用[appDelegate DeleteRecord:objInsertUpdateDelete];,但如果您的数据源没有直接从 appDelegate 获取其记录,而是从您班级中的一个数组中获取它们,您还需要从该数组中删除它。

    附带说明一下,您使用应用程序委托的设计模式可能就像一个“泥球”。 Is it good practice to use AppDelegate for data manipulation and Handling?

    【讨论】:

      【解决方案2】:

      您需要首先检查您要删除的行是否是一个部分中的唯一行。

      【讨论】:

      • 不,实际上我需要删除每个部分中的所有第一行,因为我加载到该部分的每一行中的数据来自 sqlite 数据库表的单行
      • 我不这么认为。他从 3 行开始,删除后仍有 3 行。这发生在第 0 部分,但这无关紧要。
      【解决方案3】:

      看看你的方法:

       - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      

      此方法是否总是返回正确的行数?看来您没有从支持您的部分的任何数据源中删除该行。

      编辑: 您可能正在执行删除操作,但在您的表的数据源请求新的行数时它尚未完成(或提交)。您可能需要延迟 [tableView deleteRowsAtIndexPath:] 直到数据库提交。

      【讨论】:

        猜你喜欢
        • 2014-03-12
        • 1970-01-01
        • 1970-01-01
        • 2015-12-26
        • 2020-05-08
        • 1970-01-01
        • 1970-01-01
        • 2011-08-08
        • 1970-01-01
        相关资源
        最近更新 更多