Ipad 程序接收到用于接口定向的EXC\u BAD\u访问

Ipad 程序接收到用于接口定向的EXC\u BAD\u访问,ipad,xcode4,exc-bad-access,Ipad,Xcode4,Exc Bad Access,在这段代码中,我获得了EXC\u BAD\u访问权限 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLands

在这段代码中,我获得了EXC\u BAD\u访问权限

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){
        Add1.contentStretch=CGRectMake(0.00,0.00,1024.00,66.00);
        background.image = [UIImage imageNamed:@"back2-landscape.png"];
    } else  if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){
        Add1.contentStretch=CGRectMake(0.00,0.00,768.00,66.00);
        background.image = [UIImage imageNamed:@"back2-portrait.png"];
    }
    // Return YES for supported orientations
    return YES;
}
请告诉我为什么会出现这个错误?

鸡和蛋的问题 您不应该从shouldAutorotateToInterfaceOrientation:方法内部访问interfaceOrientation属性,因为它将创建一个循环。在不知道视图控制器启用了哪些接口方向的情况下,视图控制器无法明确地告诉您它的方向是什么。请不要将其与设备的方向弄错,但在这里,您正在使用它用于确定其方向的相同方法调用它。因此,它创建了一个无限循环,从而导致崩溃


您不应使用此方法进行布局。查看LayoutSubview。

我如何在UIViewController中使用LayoutSubview?
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight))