I have added decoration view to the UICollectionView
by sub classing UICollectionViewFlowLayout
. Im placing decoration view under each row in collection view. It
s works fine. Decoration views appearing. But the problem is decoration views are not getting removed from the collection view after deleting one entire row of items. But the the header and footer views are repositioned correctly it's not handled by me. I dont know where to remove decoration view after deletion. help me. My calculation of decoration view in prepareLayout
is fine there number of decoration views and frame is correct
(Fig 1) Before deletion (Fig2) After deletion
I didn't get an answer from any of the other sources. So iam going to answer from my experience. Actually the collection view wont remove the decoration view's even supplementary views(Header/footer) after deleting the items. That you have to do manually. Probably it will be a bug in collectionView.
Remove the decoration views in the prepareLayout method
/// Collection view is not removing the added decoraion views afeter deletion. Remove yourself to fix that
for (UIView *view in self.collectionView.subviews) {
if ([view isKindOfClass:[DecorationView class]])
{
[view removeFromSuperview];
}
}
Use methods in UICollectionViewLayout
to remove supplementary/decoration View:
func prepare(forCollectionViewUpdates updateItems: [UICollectionViewUpdateItem])
func indexPathsToDeleteForSupplementaryView(ofKind elementKind: String) -> [IndexPath]
func indexPathsToInsertForDecorationView(ofKind elementKind: String) -> [IndexPath]
if you're not familiar with them, well, you should read the document really carefully
As of iOS 7 you can override -indexPathsToInsertForDecorationViewOfKind:
and -indexPathsToDeleteForDecorationViewOfKind:
in your custom layout to add/remove decoration views whenever the collection view data changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With