UIAlertview代码上的EXC_BAD_ACCESS = 1

时间:2012-11-01 11:39:49

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

我在[alert show]行上获得了EXC_BAD_ACCESS。

为什么我得到这个?

 alert = [[UIAlertView alloc]initWithTitle:@"Application Alert" message:@"all date popup" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Update",nil];

 [alert show]; //EXC_BAD_ACCESS on this line

2 个答案:

答案 0 :(得分:16)

此崩溃必须在iOS 6上。此崩溃的解决方案如下:

[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];

答案 1 :(得分:6)

只需委托代表nil,不要将自己委托给代理。如下所示编码

alert = [[UIAlertView alloc]initWithTitle:@"Application Alert" message:@"all date popup" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Update",nil];

[alert show];

如果您在委托中使用self,则必须使用alert delegate方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

然后它不会给EXC_Bad_Excess.let我知道它是否有效.. !!!!快乐编码....