我们通过reloadRowsAtIndexPaths进行更新某个或者某几个Cell的时候,在tableView内部先删除该Cell,再进行重新创建,如果我们在更新Cell的时候如果该Cell是不存在的就会Crash,attempt to delete row 10 from section 0 which only contains 0 rows before the update(试图删除不存在的Cell)
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
如何解决这个问题呢
1、通过使用reloadData进行完全重新加载;
2、判断该Cell是否存在,存在再进行reloadRowsAtIndexPaths,这样就可以避免Crash
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell) {
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}