如果在iOS11中快速连续地滑动以删除UITableView的单元格,则会崩溃

Vic*_*hoy 20 uitableview ios swipe-gesture swift

问题就像标题.这是我的代码.我发现操作,从右向左滑动直接删除,是iOS11中的新功能

let model = self.customRules.remove(at: indexPath.row)  //delete datasource
self.dao.delete(model: model) //delete data in database
tableView.beginUpdates()  //still crash no matter the line exists or not
tableView.deleteRows(at: [indexPath], with: .left) //delete cell view
tableView.endUpdates()
Run Code Online (Sandbox Code Playgroud)

这是崩溃日志.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues:'

Last Exception Backtrace:
0   CoreFoundation                      0x000000018710fd50 <redacted> + 148
1   libobjc.A.dylib                     0x0000000186624528 objc_exception_throw + 56
2   CoreFoundation                      0x000000018710fc0c <redacted> + 0
3   Foundation                          0x0000000187a9bb44 <redacted> + 112
4   UIKit                               0x00000001907c52b8 <redacted> + 648
5   UIKit                               0x00000001906819e4 <redacted> + 140
......
Run Code Online (Sandbox Code Playgroud)

Ras*_*n L 3

您的代码似乎没问题,但 Xcode 9 中存在删除单元格的错误。如果你在 Xcode 8 中尝试你的代码,它可能会工作。查看答案以获取更多信息。