I have a UITableView with several sections, and the number of sections is dynamic, that is, they can increase at any time. Reloading a section with animation on a table view where the number of sections is no big deal. I just call this:
[notesTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
However, getting this to work when the number of sections changes is such a pain. I always get that typical assertion error "The number of sections in your tableview before the reload must be the same as after the reload..etc". I understand I should use [tableView insertSections...] to get rid of this, but doing this might be difficult in my situation.
My number of sections is based of the size of an array. Is there anyway to reload sections with animations just automatically, as easy as calling [tableView reloadData], without having to worry about inserting rows and sections manually?
(I know a cheap workaround would be to use UIView animations or CAAnimation, but that doesn’t quite give the same effect as reloadSections withAnimation method.)
This is a common error when you are playing around with
FetchedViewControllers. The reason why you are getting that error is because you are deleting objects in yourdataSource, and the tableView tries to load the tableView, and looks at the delegateMethods – it shows that you have lesser sections that what is specified.You have two options :
Implement the
FetchedResultsControllerdelegate methods and implementobjectWillChange(or)objectDidChangemethod, and inside that say something likeThat should fix the problem.
Implement notifications (when you delete data under different managedObjectContexts), and post a notification when
NSManagedObjectContextDidSave(or)NSManagedObjectContextDidChange. Then you will have to add an observer to MERGE the changes with the notifications. But I doubt your problem is this serious. I would say options (1) should be sufficient.