iosswiftuicollectionviewuicollectionviewlayoutpinterest

Resizing UICollectionView with Custom Layout after adding or deleting cells in swift using Pinterest cell


I downloaded follow Pintrest Custom Layout for my CollectionView from : https://www.raywenderlich.com/4829472-uicollectionview-custom-layout-tutorial-pinterest

So the layout works fine, i got it set up so when you scroll to the bottom, I need to make it implement like pagination functionality.

Problem: If a user add or delete data from array then cells is not reflecting for their layout. For example: if I have 35 objects in array for first time and I have deleted 5 record then scrollable should be fixed to 32 objects while it is showing till 35 objects but record is displaying correctly in the case of delete. But if we add next 35 objects at runtime, then my array is having 70 records, but collection view not reloading data it still displaying 35 records.

How can i remove this space white space in the case of delete? and How can I reload it and show more cell in case of adding?

Please help.


Solution

  • Finally, I found my answer.

    just comment the given below code written in prepare function

    guard cache.isEmpty == true, let collectionView = collectionView
    else {
            return
        }
    

    and just after commented the above code, write the given below code:

    cache.removeAll()
    guard cache.isEmpty == true || cache.isEmpty == false, let collectionView = collectionView else {
                return
            }
        contentHeight = 0
    

    in the same function. it is working now finally.