iOS - reason: 'Invalid update: invalid number of rows in section 0. 错误问题修改

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 6. 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 (9), 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).'

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 2 from section 4 which only contains 0 rows before the update'

大楖是说,numberOfRowsInSection 返回的数字和 insert / delete 后,section 所包含的行数不一致。

tableViewendUpdates 方法之前,应该对标志变量做处理。endUpdates 后,会重新刷新 tableView ,numberOfRowsInSection会重新被调用。

解决方法有两种:

1, 如上所说处理好标志变量:

if ([tableView numberOfRowsInSection:4]>2) { }

2,tableview beginUpdates之前的行数对应的是前一个数据源,开始reloadcelltableview并不知道数据源发生了变化

[tableview reloadData]

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容