brightec / CustomCollectionViewLayout

Custom layout for a collection view using horizontal and vertical scrolling with sticky rows and columns
MIT License
519 stars 123 forks source link

reloadData does NOT work #25

Closed juliusbtesh closed 6 years ago

juliusbtesh commented 6 years ago

Is there a way I can use collectionView reloadData on this collection view? Every time I try to reload the data I get an error like this : 'UICollectionView received layout attributes for a cell with an index path that does not exist:

I am trying to include a search feature to filter collection results but it keeps breaking.

Any ideas on this?

adamhongmy commented 6 years ago

+1

juliusbtesh commented 6 years ago

I found a way to get this to work! Took me some time to figure it out, had to keep searching through different comments but if anyone Is interested.

I created a method named 'reload' which is set like this

- (void)reload { [self.collectionView reloadData]; self.itemAttributes = nil; [self prepareLayout]; }

So anytime I need to reload the data, I call this function instead of just the collectionView reloadData. PS: Keep in mind that the itemSize array might also need to be reset but I am using this collection view across several scripts and I am setting up the itemSize based on the controller using it

adamhongmy commented 6 years ago

but how about adding more? it seems this class is not design with all these in mind....

juliusbtesh commented 6 years ago

@adamhongmy Are you talking about adding cells? Well your data would come from an array and you can add/remove from that array during run time and then call the reload function above to reload the collection view with the new dataset

adamhongmy commented 6 years ago

@juliusbtesh that is one way to do it but reload the whole layout will cause lag if there are many data (like 200). Don't you think so?

juliusbtesh commented 6 years ago

@adamhongmy Very possible. I never really use insert or remove cells... I usually just do reload data but you make a good point