setCollectionViewLayout上的EXC_BAD_ACCESS

hpi*_*que 5 iphone exc-bad-access ios uicollectionview

如果我在方向更改期间更改UICollectionView的布局,我会EXC_BAD_ACCESS在几次旋转后得到.

- (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
}
Run Code Online (Sandbox Code Playgroud)

这是一个UICollectionView错误吗?或者我做错了什么?如果这是一个错误,有没有办法在方向更改期间更改整个布局?

我注意到在这个答案中提到了同样的问题.使用NSZombies进行调试不会产生其他信息.

jer*_*ere 1

不太确定它有什么关系,但iOS 6 的发行说明说:

\n\n
\n

、willRotateToInterfaceOrientation:duration:\n willAnimateRotationToInterfaceOrientation:duration:和\n didRotateFromInterfaceOrientation:方法不再在任何对其自身进行全屏演示的视图控制器上调用\xe2\x80\x94\n 例如,presentViewController:animated:completion:

\n\n

您应该确保您的应用程序没有使用这些方法来管理任何子视图的布局。相反,他们应该使用视图控制器 xe2x80x99sviewWillLayoutSubviews方法并使用视图xe2x80x99s 边界矩形调整布局。

\n
\n\n

由于您正在使用它,因此您UICollectionView 可能正在使用此方法来更改其布局。

\n