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 when inserting items #12

Closed
vendruscolo opened this issue Oct 2, 2015 · 4 comments
Closed

Crash when inserting items #12

vendruscolo opened this issue Oct 2, 2015 · 4 comments
Assignees
Milestone

Comments

@vendruscolo
Copy link

CollectionViewManager crashes when it checks if it shouldReloadCollectionViewToPreventInsertFirstItemIssueForUpdate

In particular, I'm asynchronously adding new items to the manager:

private func contentLoaded(resources: [Container]?, error: ErrorType?) {
    print("content loaded")

    if resources != nil {
        manager.memoryStorage.addItems(resources!)
    }
}

The manager then checks:

for indexPath in update.insertedRowIndexPaths {
    if self.collectionView.numberOfItemsInSection(indexPath.section) == 0 {
        shouldReload = true
        break
    }
}

And crashes when calls self.collectionView.numberOfItemsInSection(indexPath.section) (in that moment, there were 0 sections with 0 items).
Removing those lines make the app work correctly.

I run the app on the iOS 9 Simulator.

Exception logged:

*** Assertion failure in -[UICollectionViewData numberOfItemsInSection:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UICollectionViewData.m:566
2015-10-02 17:48:42.212 Sales App[82499:1913317] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items in section 0 when there are only 0 sections in the collection view'
@DenTelezhkin DenTelezhkin self-assigned this Oct 2, 2015
@DenTelezhkin
Copy link
Owner

That's interesting. This was a workaround, that exists from iOS 6, to fix known bug in UICollectionView, that crashes application when inserting first item in a section.

Several things to try here, first: try to replace addItems: with setItems: call. Second, can i ask you to try running this code on iOS 8, and if possible, provide an example project?

This is a workaround i always hoped to remove, however it does not seem like UICollectionView is playing nicely. I will definitely be revisiting code to see, whether it's possible to remove or clean up this workaround.

@vendruscolo
Copy link
Author

I'm sorry, but I can't reproduce the issue anymore.

Long version: I had to ship the first alpha of the project last Friday so I installed DTCollectionViewManager (I was hoping to save time: you know, the boilerplate CollectionView Data Source and Delegate). But it was crashing as I said earlier.

Today, I updated to 4.1 and started again from scratch..and it works! (using both addItems: and setItems: forSectionIndex:)
I then downgraded to ~4.0 to see if it was broken just in that version, but no, it works great also there.

So, I think I was setting up the stack in the wrong way...? (but the code seems to be the same! It's nothing more than the example in quick start section of the readme).

I'm sorry for the non-issue, I can just say thank you for the project, it's exactly what I was looking for.

@DenTelezhkin
Copy link
Owner

UICollectionView really puzzles me sometimes. I have same code running in DTTableViewManager without any workarounds whatsoever.

Ok, so let's do it this way. I am closing this issue for now, but i'll investigate collection view updates code more, hopefully i'll figure out this stuff in next versions of a framework.

Please, don't hesitate to create issue if you encounter one, i really want to make framework as stable as it can be, and other developers help and feedback are incredibly valuable to do that. 🍻

@DenTelezhkin
Copy link
Owner

DTCollectionViewManager 4.2.0 is a release, aimed at stability of UI updates and storage handling code. Underlying storage was rewritten to allow better handling of UICollectionView updates. Workaround mentioned in this issue was entirely removed from a framework. So i'm happily closing this issue 🎉

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

No branches or pull requests

2 participants