[英]EXEC_BAD_ACCESS on a UIActionSheet with ARC
Just converted a project to ARC and am now getting a EXEC_BAD_ACCESS after I dismiss a UIActionsheet, it was previously working and I am unsure if this is even ARC related. 刚刚将项目转换为ARC,而在我关闭UIActionsheet之后,现在却获得了EXEC_BAD_ACCESS,它以前正在运行,并且我不确定这是否与ARC有关。 Zombies is enabled but showing me nothing and I tried instuments and it also gave me nothing.
Zombies已启用,但什么也没给我显示,我尝试了一些尝试,但也没有给我任何帮助。
This is presented in a modal view controller, case 0, the quit button works fine but the other two give me the bad access error. 这是在模式视图控制器(情况为0)中给出的,退出按钮可以正常工作,但其他两个给我带来严重的访问错误。
This is my first conversion to ARC, am I missing something here? 这是我第一次转换为ARC,我在这里遗漏了什么吗?
Action sheet Creation: 操作表创建:
-(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];
} }
Action sheet delegate: 行动表代表:
-(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;
}
} }
If your delegate
is declared strong
in the .h file. 如果您的
delegate
在.h文件中声明为strong
。 Have you initialized the self.delegate
at least once in the .m file(preferably viewDidLoad
) using 您是否使用以下命令在.m文件(最好是
viewDidLoad
)中至少初始化了一次self.delegate
self.delegate = [[UIApplication sharedApplication] delegate];
Delegates should be weak
or assign
( __weak
/ __unsafe_unretained
for ivars) to avoid any retain cycles. 代表应为
weak
或assign
代表(对于ivars为__weak
/ __unsafe_unretained
),以避免任何保留周期。
Hold a reference to the sheet that you create. 坚持您创建的表的引用。 You can clear that reference once the sheet was closed.
关闭工作表后即可清除该参考。
Thanks everyone for the help. 谢谢大家的帮助。 I found the problem when I ran the project under xcode 4.5.
我在xcode 4.5下运行项目时发现了问题。 It gave a compile error:
switch case is protected in scope
它给出了一个编译错误:
switch case is protected in scope
I wasn't getting that error in xcode 4.3 我在xcode 4.3中没有收到该错误
It was solved in this thread When converting a project to use ARC what does "switch case is in protected scope" mean? 在该线程中解决了该问题。 将项目转换为使用ARC时,“开关大小写在保护范围内”是什么意思?
I wrapped each case in curly brackets and the problem has been fixed. 我将每种情况都用大括号括起来,问题已得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.