In UICollectionView
decoration and supplementary views seem to be a big mystery. There seems to be next to no example code at the moment. I managed to get both type
I know this is an old question but I came across this when having problems with supplementary views being duplicated all over the place when invalidating a layout. I believe it's a bug, and I fixed it by ove-riding invalidateLayout
in my layout object and removing the supplementary views as below:
- (void)invalidateLayout {
[super invalidateLayout];
// Manually remove all suplementary views of a certain type
/**
** This appears to be a BUG. Invalidate view does not remove suplementary view
** from the view hierachy. But they are Orphaned so stay on screen.
**/
for (UIView *subview in [self.collectionView subviews]) {
if ([subview isKindOfClass:[UICollectionReusableView class]]) {
[subview removeFromSuperview];
}
}
}
Replace UICollectionReusableView
with the class of your re-usable view that is being left on screen.
Hope this helps someone.