NHBalancedFlowLayout icon indicating copy to clipboard operation
NHBalancedFlowLayout copied to clipboard

Adding new items to the collection rearranges old cells

Open limenutt opened this issue 10 years ago • 3 comments

Hi there. In my Photozeen iOS app I'm loading more images to the photo feed as user scrolls it down. Every time I have new portion of images from server I add them to the collection by calling insertItemsAtIndexPaths. I see that items are getting rearranged every time. What can I do to make previously loaded items stay still except adding new section for every new portion of images?

limenutt avatar Mar 12 '14 10:03 limenutt

Are you adding every new batch of items to a different section, or are all the images in the same section. The layout is calculated per section, so adding a new section should allow the previous section to remain unchanged. Although I'm not sure if it would redo the calculation for the previous sections as well.

njdehoog avatar Mar 13 '14 08:03 njdehoog

Yes, currently I'm using only one section and was looking for workaround without adding new section for every new batch. But looks like it is the only solution, am I right?

limenutt avatar Mar 13 '14 08:03 limenutt

That's right. The implementation of the layout algorithm is such that it tries to determine the best possible layout based on every image in a section, so every time you add a new image it is likely to affect the layout.

njdehoog avatar Mar 13 '14 08:03 njdehoog