Exception handling for a UITableView delete operation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.