iOS TableView reloadRowsAtIndexPaths Crash报异常
异常信息:
NSInternalInconsistencyException
attempt to delete row 0 from section 0 which only contains 0 rows before the update
通过reloadRowsAtIndexPaths刷新cell时,会概率性出现上面崩溃信息问题。
原因:
在调用reloadRowsAtIndexPaths方法时,tableview是要依赖先前已有的cell状态更新,首先会删除该cell,然后重新创建。所以在原先没有该cell的状态下调用reloadRowsAtIndexPaths方法,会报异常(尝试不存在的cell)
解决方法:
1、使用reloadData
2、调用时判断需要刷新的cell是否存在,存在再调用reloadRowsAtIndexPaths。