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

NSInternalInconsistencyException #27

Closed
iBachek opened this issue Dec 13, 2021 · 5 comments
Closed

NSInternalInconsistencyException #27

iBachek opened this issue Dec 13, 2021 · 5 comments
Assignees
Labels
help wanted Extra attention is needed invalid This doesn't seem right

Comments

@iBachek
Copy link

iBachek commented Dec 13, 2021

Hi, thank u for the new chat behaviour.

I faced with crash on your example app, you can reproduce it, if replace your code in DefaultChatController

Reason: invalid number of sections. The number of sections contained in the collection view after the update (170) must be equal to the number of sections contained in the collection view before the update (89), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted).

change line 147

DispatchQueue.main.async { [weak self] in
    guard self != nil else {
        return
    }
    completion([Section(id: 0, title: "Loading...", cells: Array(cells))])
}

to

DispatchQueue.main.async { [weak self] in
    guard self != nil else {
        return
    }

    let sections = Array(cells).map { cell in
        Section(id: cell.differenceIdentifier, title: "New Section", cells: [cell])
    }

    completion(sections)
}
@ekazaev
Copy link
Owner

ekazaev commented Dec 13, 2021

@iBachek Morning. I am not sure why you did that modification in the first place - you wrapped each cell into a section. The Example app doesn't support more then one section. If you need more then one section - you will have to modify the other parts of the app.

PS: About supplementary views in general see https://github.com/ekazaev/ChatLayout#about-supplementary-views

@ekazaev ekazaev added help wanted Extra attention is needed invalid This doesn't seem right labels Dec 13, 2021
@ekazaev ekazaev self-assigned this Dec 13, 2021
@iBachek
Copy link
Author

iBachek commented Dec 13, 2021

@ekazaev section header has a visibility behavior when scrolling and snapping to the top, this is necessary to separate messages by date

@iBachek
Copy link
Author

iBachek commented Dec 13, 2021

@iBachek Morning. I am not sure why you did that modification in the first place - you wrapped each cell into a section. The Example app doesn't support more then one section. If you need more then one section - you will have to modify the other parts of the app.

PS: About supplementary views in general see https://github.com/ekazaev/ChatLayout#about-supplementary-views

what parts do you mean?

@ekazaev
Copy link
Owner

ekazaev commented Dec 14, 2021

Firstly. This doesnt discount my comment above. If you want to have more then one section - you need to modify the rest of the app. Ill have a look.

Secondly: Snapping header to the top is not supported by the layout itself. So if you need this behavior you'll need to implement it yourself. My assumption is that you need to create a fake date view at the top of the container view that will hold your collection view and track the visibility of the date cell within the collection view and if it is above the top boundary of the collection view - make your fake date view visible.

See also #18

@ekazaev
Copy link
Owner

ekazaev commented Dec 14, 2021

About what parts to modify: At least you need to comment out the scrolling to the last item in ChatViewController line 470 as there is an incorrect calculation. Also comment out lines 461-463. Then it should work:
Screenshot 2021-12-14 at 10 22 29
Then you need to fix your code in the way you are currently using difference identifier for the section. In your current variant you are making update operations over entire section. Basically you reload entire section with all the cells inside and and its headers and footers. So you will see small jumps in the UI.
Ill warn you again. Do not use headers or footers for the decoration of your groups of messages. There is no command in UICollectionView that allows you to update them individually. You can reload the entire section only with all the items and supplementary views inside. And I am not even touching other limitations of the supplementary view.

@ekazaev ekazaev closed this as completed Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants