Skip to content
This repository was archived by the owner on Nov 15, 2020. It is now read-only.
This repository was archived by the owner on Nov 15, 2020. It is now read-only.

Fixed assertion failure when reloading with animations #4

@geraldeersteling

Description

@geraldeersteling

Hello,

Great work on the Kit, I really like the setup. I do encounter an assertion failure when trying to use reloading with animations.

I'm creating a viewcontroller with a tableview which includes search. The content (models) are supplied through an JSON (which is parsed to a correct ModelProtocol).
Everything goes fine if I use/reload the tableview without animations, but as soon as I use reloadData(after:onEnd:) my app crashes with an assertion failure.

Here is a snippet of my code:

override public func viewDidLoad() {
    super.viewDidLoad()

    director = tableView.director
    director?.rowHeight = .autoLayout(estimated: UITableViewAutomaticDimension)
    let adapter = TableAdapter<Contact, ContactCell>()
    director?.register(adapters: [adapter])
}

public func updateSearchResults(for searchController: UISearchController) {
    // Assume the models contain valid `Contact` objects retrieved from the JSON
    let models = retrieveContacts()
    DispatchQueue.main.async {
        self.director?.reloadData(after: {
            $0.removeAll()
            $0.add(section: TableSection(result?.resultCollection))
            return .default()
        })
    }
}

The above snippet triggers an assertion exception which tells:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (0), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'

This happens even if I remove the line $0.removeAll(). Somehow the deleteSections is not working properly.

Am I doing something wrong here?

Thanks

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions