8

我在 [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
4

2 回答 2

16

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

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

于 2012-11-01T12:16:12.533 回答
6

只需将委托设为 nil,不要将 self 应用于委托。代码如下

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

[alert show];

如果您在委托中使用自我,那么您将不得不使用警报委托方法

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

那么它不会给 EXC_Bad_Excess。让我知道它是否有效..!!!!快乐编码....

于 2012-11-01T11:50:40.553 回答