IOS11Crash:UITableView Invalid update

On the iOS11 system, when a cell is deleted, a new cell is added, and then the UITableView is refreshed, Crash must appear.

The tip is probably this:

IOS11Crash:UITableView Invalid update
crash.png

Its main meaning is that you obviously deleted one, but when you refresh, the number of cell returned is the original, so crash, apple is using the magic AI, is not the apple pot? As for why iOS11 will, I did not find the results, I hope a good hearted person told me.

Kernel code:

/ / delete a and add a data source - (void) resetdataSourceWithIndex: (NSInteger) {NSMutableArray *mTempArr = [NSMutableArray index arrayWithArray:self.dataSource]; [mTempArr removeObjectAtIndex:index]; [mTempArr addObject:[NSString stringWithFormat:@ "test%@", "@ (self.num + 1); self.num + +; self.dataSource = mTempArr;}
- (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath * indexPath) {if (self.dataSource.count - 1 < indexPath.row) {return}; if (editingStyle = = UITableViewCellEditingStyleDelete) {/ / first delete the data source [self resetdataSourceWithIndex:indexPath.row] tableView [self.tableView reloadData]; / / set;}}

After the deletion of cell, in the case of the number of data sources unchanged, the direct call [self.tableView reloadData] to refresh the tableView, iOS11 directly on the crash, interested students can also personally try.

My current solution is to replace it with a refresh method:

- (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath * indexPath) {if (self.dataSource.count - 1 < indexPath.row) {return}; if (editingStyle = = UITableViewCellEditingStyleDelete) {[self resetdataSourceWithIndex:indexPath.row]; [self.tableView beginUpdates] [self.tableView; reloadSections:[[NSIndexSet alloc]initWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic]; self.tableView endUpdates] ";}}

If you have any good idea or what’s wrong with my understanding, please leave a message.