Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in TableViewSectionDataSource when showing and hiding a section #288

Open
igorkulman opened this issue Feb 7, 2019 · 5 comments
Open

Comments

@igorkulman
Copy link
Contributor

igorkulman commented Feb 7, 2019

In my project I have a chat detail with a list of messages. I use the RxTableViewSectionedAnimatedDataSource with two sections.

In most cases, only the section with the messages is shown but when the user scrolls to the top of the table view, I set the isLoading property so an additional section at the top is shown with just 1 cell showing a spinner.

let data = Observable.combineLatest(viewModel.messages.asObservable(), viewModel.isLoading.asObservable()) { (messages: [Message], isLoading: Bool) -> [AnimatableLoaderSectionModel] in
        var sections: [AnimatableLoaderSectionModel] = []
        if isLoading {
            sections.append(.LoaderSection)
        }
        sections.append(.ItemsSection(items: messages.map({ .Item(item: $0) })))
        return sections
}

After loading the older messages is done isLoading is set back to false and the new messages appear in viewModel.messages.

This works fine most of the times, but when I scroll to top really fast doing it again and again I get a crash in https://github.com/RxSwiftCommunity/RxDataSources/blob/master/Sources/RxDataSources/TableViewSectionedDataSource.swift#L190.

When I do not append the .LoaderSection when constructing data then it does not happen, ever.

To be more exact, in the method

open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        precondition(indexPath.item < _sectionModels[indexPath.section].items.count)

The indexPath is for example section=1, row=6 but the _sectionModels only have 1 item, resulting in an out fo bound crash basically.

It looks like the data source is trying to update some item and still thinks the
.LoaderSection exists (so .LoaderSection is section=0 and the update is for section=1) but the _sectionModels does not contain the .LoaderSection anymore.

@RafaelPlantard
Copy link

I guess I'm going through the same situation, do you have any solution?

@mkko
Copy link

mkko commented Mar 4, 2019

I'd gladly try to check this but do you have some kind of reduced example?

@RafaelPlantard
Copy link

My issue was with other not disposable sequence, not related with TableViewSectionDataSource, thanks for asking @mkko

@okycelt
Copy link

okycelt commented Jan 21, 2020

@RafaelPlantard, could you share what exactly was the issue on your end? I think I'm facing the same problem now with a similar use case like @igorkulman.

@SolitaryWolf
Copy link

I have same issue. In my case my tableview �continuously append and remove cell using accept data to datasource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants