Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView internal bug: unable to generate a new section map with old section count: and new section count: with userInfo (null)

I haven't seen this error before, and I did a search as to why it may be happening but couldn't find any info on it:

CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. UITableView internal bug: unable to generate a new section map with old section count: 1 and new section count: 0 with userInfo (null)

Does anyone know what might be happening here? I am not sure about the "internal bug" part - does this error indicate a problem with my code or a bug in UITableView?

like image 581
SAHM Avatar asked Oct 19 '22 09:10

SAHM


2 Answers

Stephan already mentioned this in a comment on the original question but I thought it was worth sharing some code. This answer was actually sourced from a comment made by user GERUB on a thread on the apple dev forums found here: https://forums.developer.apple.com/thread/9964

if tableView.numberOfRowsInSection(indexPath.section) == 1{  
    tableView.deleteSections(NSIndexSet(index: indexPath.section), withRowAnimation: .Automatic)  
}else{  
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)  
} 

I have tested this inside of the NSFetchedResultsControllerDelegate method implementations and it works perfectly.

like image 161
user3344977 Avatar answered Nov 04 '22 20:11

user3344977


Did you use this NSFetchedResultsController in multiple UITableView. If so, that's the cause. Use one NSFetchedResultsController for one UITableView. Do not just switch queries when switching views.

like image 33
hebinda Avatar answered Nov 04 '22 20:11

hebinda