Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert UITableView internal inconsistency prefetchedCells and indexPathsForPrefetchedCells are out of sync

Using UITableView with a custom cell. This was working fine till using iOS SDK 14. When start using iOS sdk 15, UITableView gives error upon scrolling.

Error is "Assert UITableView internal inconsistency prefetchedCells and indexPathsForPrefetchedCells are out of sync"

Because of this error cells starts disappear randomly.

like image 342
kapill Avatar asked Jan 25 '26 23:01

kapill


1 Answers

This assert indicates that the UITableView internal state is "corrupted". The most frequent cause is when the table view is performing an update or reload, and is in the middle of a callback to one of the data source or delegate methods, and somehow your code causes unexpected "reentrancy" on the UITableView (e.g. by performing another update/reload or by manually running the main runloop) from inside this callback. This causes UITableView to get into an inconsistent internal state because it's already in the middle of processing another update.

In my case I have a bad interaction between UITableView and the NSAttributedString() init method that using SwiftSoup to converts html to an attributedString. It was being called while updating a tableViewCell and this caused cellForRowAt to be called again while my app code was already processing a cellForRowAt call. And the tableView lost its mind after that.

I fixed this problem by converting html to an attributedString earlier before cellForRowAt run, then cellForRowAt using it.

like image 71
user1578860 Avatar answered Jan 28 '26 16:01

user1578860



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!