繁体   English   中英

带有ARC的UIActionSheet上的EXEC_BAD_ACCESS

[英]EXEC_BAD_ACCESS on a UIActionSheet with ARC

刚刚将项目转换为ARC,而在我关闭UIActionsheet之后,现在却获得了EXEC_BAD_ACCESS,它以前正在运行,并且我不确定这是否与ARC有关。 Zombies已启用,但什么也没给我显示,我尝试了一些尝试,但也没有给我任何帮助。

这是在模式视图控制器(情况为0)中给出的,退出按钮可以正常工作,但其他两个给我带来严重的访问错误。

这是我第一次转换为ARC,我在这里遗漏了什么吗?

操作表创建:

-(IBAction)quitPressed:(id)sender {
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Quit This Game?"    delegate:self cancelButtonTitle:@"Keep Playing" destructiveButtonTitle:@"Quit" otherButtonTitles:@"Quit and Reveal Answers",nil];
    [sheet showInView:self.view];

}

行动表代表:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    switch (buttonIndex) {
        case 0:  //quit
            [self dismissViewControllerAnimated:NO completion:^{
            [self.delegate quitGame];
        }];
        break;
        case 1:  //quit and reveal
            NSLog(@"reveal");
            break;
        case 2: //cancel
            NSLog(@"cancel"); 
            break;
        default:
        break;
    }

}

如果您的delegate.h文件中声明为strong 您是否使用以下命令在.m文件(最好是viewDidLoad )中至少初始化了一次self.delegate

self.delegate = [[UIApplication sharedApplication] delegate];

代表应为weakassign代表(对于ivars为__weak / __unsafe_unretained ),以避免任何保留周期。

坚持您创建的表的引用。 关闭工作表后即可清除该参考。

谢谢大家的帮助。 我在xcode 4.5下运行项目时发现了问题。 它给出了一个编译错误: switch case is protected in scope

我在xcode 4.3中没有收到该错误

在该线程中解决了该问题。 将项目转换为使用ARC时,“开关大小写在保护范围内”是什么意思?

我将每种情况都用大括号括起来,问题已得到解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM