chiahsien/CHTCollectionViewWaterfallLayout

⚠️The #116 is a new BUG !

madordie opened this issue · 8 comments

#166 @rafaelcr @chiahsien

I find header attributed AND footer attributed THED merge return attributed

so . header and footer KEY == [NSIndexPath indexPathForItem:0 inSection:section]

The result is that the footer will MUST replace the header

Hi @madordie ,
Thanks for the information, but I don't have time to work on this.
Could you send a PR to fix this bug?

@madordie I'm sorry, I don't fully understand your comment.

If you're saying that the footer and header must not replace each other when they have the same indexPath, then you could change the code so that it not only separates elements into different NSDictionarys by their representedElementCategory but also by their representedElementKind.

@rafaelcr

My English is not very good, so I use this Google Translate
😂😂😂


DEMO-CHT # 166BUG

Reproduce the BUG described in #174.

The main steps

In the UICollectionViewWaterfallLayout.m -> - (void) prepareLayout, set NSIndexPath indexPathForItem: 0 inSection: section]`

In the UICollectionViewWaterfallLayout.m -> - (NSArray *) layoutAttributesForElementsInRect: (CGRect) rect, using the NSDictionary as the storage structure, use attr`` NSIndexPath as the NSDictionary key

So, when UICollectionViewWaterfallLayout.m -> - (NSArray *) layoutAttributesForElementsInRect: (CGRect) rect need to return both header and footer 'will appear. That is, value1 in dict will be replaced by value2.

NSMutableDictionary * dict = [NSMutableDictionary dictionary];
dict[@ "KEY"] = @ "value1";
dict[@ "KEY"] = @ "value2";

I wrote a demo

If it is my usage problem, we can discuss this issue together 😊


DEMO-CHT#166BUG

重现#174中所描述的BUG。

主要步骤

UICollectionViewWaterfallLayout.m -> - (void)prepareLayout 中,设置headerfooter使用的NSIndexPath定义均为[NSIndexPath indexPathForItem:0 inSection:section]

UICollectionViewWaterfallLayout.m -> - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect中,采用了NSDictionary作为存储结构,使用attrNSIndexPath作为NSDictionary的key

所以,当UICollectionViewWaterfallLayout.m -> - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect需要同时返回headerfooter将会出现headerfooter替换的现象。即:dict中的value1将被value2所替换。

NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[@"KEY"] = @"value1";
dict[@"KEY"] = @"value2";

我写了一个demo

如果是我的用法问题,我们可以一起在讨论一下这个问题😊

I got same error.
My collectionView have 1 section with header and footer, but only CHTCollectionElementKindSectionFooter passing in
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

@madordie thanks, I just submitted a new PR and realized you made the exact same change 😝

😊

#179

@chiahsien need update tag for cocoapods 😂

okay, new tag published!