为什么只有AppDelegate的BOOL属性才会抛出EXC_BAD_ACCESS?

时间:2014-08-26 08:33:33

标签: ios objective-c iphone xcode exc-bad-access

在appdelegate.h

@property (nonatomic,assign) bool isPhone;

在appdelegate.m

if ( IDIOM == IPAD ) {
        self.isPhone = NO;
        objDrawing = [[DEDrawingPage alloc]initWithNibName:@"DEDrawingPageiPad" bundle:nil];

    } else {
        self.isPhone = YES;
        objDrawing = [[DEDrawingPage alloc]initWithNibName:@"DEDrawingPageiPhone" bundle:nil];

    }

+(DEAppDelegate *)getDelegate
{
    return (DEAppDelegate *)[[UIApplication sharedApplication] delegate];
}

在viewController.m中

if([DEAppDelegate getDelegate].isPhone) // bad access here
    {
        objSettingPage = [[DESettings alloc]initWithNibName:@"DESettingsiPhone" bundle:nil];

    }

访问isPhone属性会导致IF条件无法访问。仅在BOOL类型属性中发生这种情况。我试过服用NSNumber或NSString。他们工作正常。为什么BOOL提供不良访问权限。我也试过(小写)布尔,这也没用。

2 个答案:

答案 0 :(得分:0)

您可以清理构建并重新检查问题。我遵循了上述相同的步骤,没有遇到问题。

另外,您是否在delegate.h中定义了以下内容

+(DEAppDelegate *)getDelegate;

答案 1 :(得分:0)

为什么不在您macro appDelegate的所有object use中使用下面给出的application define project's {1}} .pch file

#define appDelegateObject ((AppDelegate *)[UIApplication sharedApplication].delegate)

注意change AppDelegateApplication Delegate instance

像这样使用这个宏:

if(appDelegateObject.isPhone) //Here isPhone is property of appDelegate
{
    //anything here
}
相关问题