8

I am getting the EXC_BAD_ACCESS on [alert show] line.

Why I am getting this?

 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
Aitul
  • 2,982
  • 2
  • 24
  • 52
swati sharma
  • 367
  • 4
  • 15

2 Answers2

16

This crash must be on iOS 6. Solution for this crash is as follow :

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

Devang
  • 11,258
  • 13
  • 62
  • 100
  • 3
    This is the correct solution if it errs because you are calling `[alert show]` from the background. – Hlung Feb 10 '13 at 08:37
6

Just make delegate nil ,don't apply self to delegate .code it like below

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

[alert show];

if you are using self in delegate then you will have to use alert delegate method

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

then it will not give EXC_Bad_Excess.let me know if it works..!!!!happy coding....

NiravPatel
  • 3,260
  • 2
  • 21
  • 31