hpique
hpique

Reputation: 120344

EXC_BAD_ACCESS on setCollectionViewLayout

If I change the layout of a UICollectionView during an orientation change, I get EXC_BAD_ACCESS after a few rotations.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    UICollectionViewLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    self.myCollectionView.collectionViewLayout = layout; // This causes EXC_BAD_ACCESS after a few rotations
}

Is this a UICollectionView bug? Or am I doing something wrong? If it's a bug, is there any way to change the whole layout during an orientation change?

I noticed that the same problem is mentioned in this answer. Debugging with NSZombies does not produce additional information.

Upvotes: 5

Views: 1894

Answers (1)

jere
jere

Reputation: 4304

Not quite sure it has something to do but the Release Notes for iOS 6 say:

The willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:, and didRotateFromInterfaceOrientation: methods are no longer called on any view controller that makes a full-screen presentation over itself—for example, presentViewController:animated:completion:

You should make sure that your apps are not using these methods to manage the layout of any subviews. Instead, they should use the view controller’s viewWillLayoutSubviews method and adjust the layout using the view’s bounds rectangle.

Since you are using UICollectionView maybe it has something to do that you are using this method to change its layout.

Upvotes: 1

Related Questions