Phenomenon: When a row is deleted, the following exception message appears
' Nsinternalinconsistencyexception ', Reason: ' Invalid update:invalid number of rows in section 0. The number of rows contained in a existing section after the update (5) must is equal to the number of rows contained in That sections before the update (5), plus or minus the number of rows inserted or deleted from (0 inserted, 1 deleted) and plus or minus the number of rows moved into an or out of (0 moved in, 0 moved out). '
Reason:
Usually appears to execute this sentence when the error:
TableView. deleterowsatindexpaths ([Indexpath], withrowanimation: uitableviewrowanimation. Automatic)
In fact, the following NUM does not match the number of rows deleted.
For example, the actual number of rows after deletion is 5, and num of the following method is generally the count of an array, and when the elements of the array forget remove, count may be 6, which results in an error.
func TableView (tableView: uitableview, numberofrowsinsection section: Int), int{
The return num//error is due to the inconsistency between NUM and delete rows here
}
Solution:
After executing core data or deleting the database
Performs a remove element operation on an array that provides storage data to table in the corresponding Viewcontroller
Re-execute deleterowsatindexpaths
This article from "Graceful Swift" blog, declined reprint!
Exception handling for a UITableView delete operation