简体   繁体   English

删除带有动画的单元格时发生错误

[英]Error Occurs When Deleting Cell with Animation

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

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

PeopleManager Class have a people array (NSMutableArray). PeopleManager类具有一个人员数组(NSMutableArray)。

My error is not Index value error. 我的错误不是索引值错误。

It works fine 99.9% without error. 它正常工作99.9%,没有错误。 But sometimes error occur 但有时会发生错误

Error Code 错误代码

2012-02-03 17:17:53.232 PhoneBook[343:707] * Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1912.3/UITableView.m:1046 2012-02-03 17:17:53.239 PhoneBook[343:707] * 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 (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).' 2012-02-03 17:17:53.232电话簿[343:707] *-[UITableView _endCellAnimationsWithContext:],/ SourceCache / UIKit / UIKit-1912.3 / UITableView.m的断言失败:m:1046 2012-02-03 17:17: 53.239 PhoneBook [343:707] *由于未捕获的异常“ NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:部分0中的行数无效。更新(1)之后现有部分中包含的行数必须相等到更新之前该部分中包含的行数(1),加上或减去从该部分插入或删除的行数(插入0,删除1),加上或减去移入或删除该行的行数部分(移入0,移出0)。” terminate called throwing an exceptionkill 终止称为抛出异常杀死

How can fix it??? 如何解决??? I read error code.but I do not know how to fix it... 我读了错误代码。但我不知道如何解决...

you should wrap your deleteRows... call in a beginUpdates and endUpdates pair: 您应该在beginUpdates和endUpdates对中包装好deleteRows ...调用:

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

and make sure that your numberOfRowsForSection: method returns the correct updated value 并确保您的numberOfRowsForSection:方法返回正确的更新值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM