Prevent multiple layout attrs for the same object#166
Merged
chiahsien merged 2 commits intochiahsien:developfrom May 23, 2017
Merged
Prevent multiple layout attrs for the same object#166chiahsien merged 2 commits intochiahsien:developfrom
chiahsien merged 2 commits intochiahsien:developfrom
Conversation
I've been getting a crash recently when trying to add headers to sections using your layout:
```
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'layout attributes for supplementary item at index path (<NSIndexPath: 0xc000000000000116> {length = 2, path = 1 - 0}) changed from <UICollectionViewLayoutAttributes: 0x6100003e1f00> index path: (<NSIndexPath: 0xc000000000000116> {length = 2, path = 1 - 0}); element kind: (CHTCollectionElementKindSectionHeader); frame = (0 490; 768 20); to <UICollectionViewLayoutAttributes: 0x6080003e1200> index path: (<NSIndexPath: 0xc000000000000116> {length = 2, path = 1 - 0}); element kind: (CHTCollectionElementKindSectionHeader); frame = (0 530; 768 20); without invalidating the layout'
```
What I noticed is that multiple attributes were being generated for the same index path in `layoutAttributesForElementsInRect` so the `UICollectionView` got confused towards which one to use. This fix prevents that from happening.
chiahsien
reviewed
May 23, 2017
| NSMutableArray *attrs = [NSMutableArray array]; | ||
| NSMutableDictionary *cellAttrDict = [NSMutableDictionary dictionary]; | ||
| NSMutableDictionary *supplAttrDict = [NSMutableDictionary dictionary]; | ||
| NSMutableDictionary *decorAttrDict = [NSMutableDictionary dictionary]; |
Owner
There was a problem hiding this comment.
Do we really need 3 dictionaries? Or what we need is one dictionary and use attr.indexPath as the key?
Contributor
Author
There was a problem hiding this comment.
The problem is indexPaths can be the same and collide between each of those three object categories. I actually tried that approach on the first commit but it didn't work because of that. Items were overwritten by decorators or supplemental views and viceversa.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've been getting a crash recently when trying to add headers to sections using your layout:
What I noticed is that multiple attributes were being generated for the same index path in
layoutAttributesForElementsInRectso theUICollectionViewgot confused towards which one to use. This fix prevents that from happening.