قالب وردپرس درنا توس
Home / IOS Development / My tableview crashes if I call `insertRows` while rotating the device. Can anyone suggest something fix? : iOSProgramming

My tableview crashes if I call `insertRows` while rotating the device. Can anyone suggest something fix? : iOSProgramming



EDIT: I was able to solve my problem using this answer. Basically put the new comments in a temporary array before adding it to the main radius: https://stackoverflow.com/a/56181552/1634905

I need to analyze a lot of data to display in my table view. So instead of analyzing all the data and then uploading the table view, I stop analyzing 50 rows of data, inserting it so that the user has something to see right away, and while I continue to analyze the rest of the data and insert 50 more every time. This works perfectly if I do not rotate the device, but if I rotate while still adding data, my app crashes.

Here I add the data and check if it has added 50 rows of data:

  itself. comments.append (currentComment)

indexPathsToAdd.append (IndexPath (rad: self.comments.count - 1, section: 1))

if self.comments.count% 50 == 0 {
self.addRowsIfNeeded (indexPathsToAdd: indexPathsToAdd)
indexPathsToAdd.removeAll ()
}

How to insert the rows:

  func addRowsIfNeeded (indexPathsToAdd: [IndexPath]) {
if indexPathsToAdd.count> 0 {
DispatchQueue.main.async {
self.myTableView.startUpdates ()
self.myTableView.insertRows (at: indexPathsToAdd, with: .fade)
self.myTableView.endUpdates ()
}
}
}

The error message is usually:

  *** Disclaimer in - [APPNAME.GodTableView _endCellAnimationsWithContext:] /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3698.84.15/UITableView.m: 2055 *** Exit the app because of the uncaught exception & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; NSInternalInconsistencyException & # 39 ;, cause: & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; invalid update: invalid number of rows in section 1. The number of rows contained in an existing section after the update (150) must be equal to the number of rows found in that part before the update (127), plus or minus the number of rows inserted or deleted from that part (50 inserted, 0 deleted) and plus or minus the number of rows moved in or out of that part (0 moved in, 0 moved out). & # 39;

But sometimes I also get this weird error, which I have no idea what it means:

malloc: Incorrect checksum for released object 0x1509c7000: probably changed after being released. Corrupt value: 0x71


Source link