删除分组表的行时出现问题
大家好,
我正在使用以下代码来删除 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]
*** 由于未捕获的异常而终止应用程序
'NSInternalInconsistencyException', 原因:'无效更新:无效 第 0 节中的行数。 包含的行数 更新后现有部分 (3) 必须等于行数 包含在该节之前 更新(3),加减数字 从中插入或删除的行数 部分(0 插入,1 删除)。'
有朋友可以帮帮我吗?提前感谢
hii every one
i am using following code to delete a row in the rgouped table view
- (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];
}
}
}
but its crashing at the line
[tableView1 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
crash log is:
2011-05-20 19:21:20.233
iICS[10744:207] * Assertion failure
in -[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',
reason: 'Invalid update: invalid
number of rows in section 0. The
number of rows contained in an
existing section after the update (3)
must be equal to the number of rows
contained in that section before the
update (3), plus or minus the number
of rows inserted or deleted from that
section (0 inserted, 1 deleted).'
can any buddy help me? thanx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在调用
deleteRowsAtIndexPaths:
之前,请确保您的数据源反映了您所做的更改。我看到您正在调用[appDelegate DeleteRecord:objInsertUpdateDelete];
但如果您的数据源没有直接从 appDelegate 获取其记录并从类中的数组获取它们,您还需要将其删除来自该数组。附带说明一下,您使用应用程序委托的设计模式可能就像一个“泥球”。 将 AppDelegate 用于数据操作和处理?
Make sure that your data source is reflecting the changes you are making before calling
deleteRowsAtIndexPaths:
. I see that you are calling[appDelegate DeleteRecord:objInsertUpdateDelete];
but if your data source is not getting its records directly from the appDelegate and getting them from maybe an array in your class you also need to remove it from that array.As a side note your design pattern for using the app delegate may be like a "ball of mud". Is it good practice to use AppDelegate for data manipulation and Handling?
您需要首先检查要删除的行是否是部分中的唯一行。
You need to first check if the row you're deleting is the only row in a section.
查看您的方法:
此方法是否始终返回正确的行数?看来您没有从支持您的部分的任何数据源中删除该行。
编辑:
您可能正在执行删除操作,但在表的数据源请求新行计数时它尚未完成(或提交)。您可能需要延迟 [tableView deleteRowsAtIndexPath:] 直到数据库提交。
Look in your method:
Does this method always return the correct row count? It seems you're NOT removing the row from whatever datasource is backing your section.
EDIT:
It's possible you are doing the delete, but it has not completed (or committed) at the time your table's dataSource is asking for the new rowcount. You might need to delay your [tableView deleteRowsAtIndexPath:] until the database commits.