UIAlertview代码上的EXC_BAD_ACCESS = 1

swa*_*rma 8 iphone xcode exc-bad-access objective-c uialertview

我在[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
Run Code Online (Sandbox Code Playgroud)

Dev*_*ang 16

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

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

  • 如果错误,这是正确的解决方案,因为你从后台调用`[alert show]`. (3认同)

Nir*_*tel 6

只需要委托nil,不要将自己委托给代理.如下所示

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

[alert show];
Run Code Online (Sandbox Code Playgroud)

如果你在委托中使用self,那么你将不得不使用alert delegate方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
Run Code Online (Sandbox Code Playgroud)

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