使用动画删除单元格时出错

时间:2012-02-03 08:29:21

标签: iphone uitableview

[[PeopleManager shared] removePersonAtIndex:indexPath.row withGroupIndex:currentGroupIndex];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationNone];

PeopleManager类有一个people数组(NSMutableArray)。

我的错误不是索引值错误。

它没有错误地工作得很好99.9%。但有时会发生错误

错误代码

  

2012-02-03 17:17:53.232电话簿[343:707] *断言失败    - [UITableView _endCellAnimationsWithContext:],/ SourceCache / UIKit / UIKit-1912.3 / UITableView.m:1046       2012-02-03 17:17:53.239 PhoneBook [343:707] * 由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:   '无效更新:第0节中的行数无效。数量   更新(1)后必须包含在现有部分中的行   等于之前该部分中包含的行数   更新(1),加上或减去插入或删除的行数   该部分(0插入,1删除)和加号或减号的数量   行移入或移出该部分(0移入,0移出)。       终止叫做抛出异常

如何解决?我读错误代码。但我不知道如何解决它......

1 个答案:

答案 0 :(得分:0)

你应该在beginUpdates和endUpdates对中包装你的deleteRows ...调用:

[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationNone];
[tableView endUpdates];

并确保numberOfRowsForSection:方法返回正确的更新值