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.
Not quite sure it has something to do but the Release Notes for iOS 6 say:
The
willRotateToInterfaceOrientation:duration:
,willAnimateRotationToInterfaceOrientation:duration:
, anddidRotateFromInterfaceOrientation:
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.
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