UITableView的insert和delete操作与numberOfRowsInSection同步问题

问题描述:通过CrashRepoter得到如下报错信息:
Application Specific Information:
*** 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 (0) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 3 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

问题解决:在[self.tableView insertRowsAtIndexPaths:withRowAnimation:]和[tableView deleteRowsAtIndexPaths:withRowAnimation:]进行修改的操作前后加保护:
[tableView beginUpdates]和[self.tableView endUpdates]

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注