0

I'm switching between layouts in a uicollectionview using this code

-(void)setHorizontalLayout:(BOOL)layout
{
    if (layout == YES)
    {

        [self.collectionView performBatchUpdates:^{
            [self.collectionView setCollectionViewLayout:self.horizontalPagingLayout animated:NO];
            [self.collectionView setPagingEnabled:YES];
            self.galleryInHorizontalScrollMode = YES;
        } completion:^(BOOL finished) {
            [self.collectionView reloadData];
        }];
    }
    else {


        [self.collectionView performBatchUpdates:^{

            [self.collectionView setCollectionViewLayout:self.galleryLayout animated:NO];
            self.galleryInHorizontalScrollMode = NO;
            [self.collectionView setPagingEnabled:NO];
        } completion:^(BOOL finished) {
            [self.collectionView reloadData];
        }];
    }

    return;
}

but after I change from one layout to the other I am getting the [0,0] indexpathed cell set as the uicollectionview's background. I suspect something with the layer is messed up. And looking over the call stack all looks fine. I can't see any calls to animations that may be messing with the layer.

Any way to invalidate this? what could cause it?

Avba
  • 14,822
  • 20
  • 92
  • 192
  • What does "cell set as the uicollectionview's background" mean? Literal interpretation: the collection view's `backgroundView` property is a cell instance. Likely interpretation: the cell's frame is equal to the collection view's bounds. – Timothy Moose Aug 25 '13 at 15:58

1 Answers1

0

I'm not sure on why this behavior happens but when I invalidated the layout before changing the layout all works as expected:

[self.collectionView performBatchUpdates:^{
            ***[self.collectionView.collectionViewLayout invalidateLayout];***
            [self.collectionView setCollectionViewLayout:self.horizontalPagingLayout animated:NO];
        } completion:^(BOOL finished) {
            [self.collectionView reloadData];
        }];
Avba
  • 14,822
  • 20
  • 92
  • 192