5

I have this code:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

The problem is this code crash before it shows the alert, I have tested it on lower iOS and it work but on iOS 6 it crash.

Arnlee Vizcayno
  • 2,405
  • 3
  • 23
  • 31

1 Answers1

10

I found the answer. I coded:

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

instead of

[alert show];

it crash because the process might not be performed in the main thread.

Source from: https://stackoverflow.com/a/12475858/1179680

Community
  • 1
  • 1
Arnlee Vizcayno
  • 2,405
  • 3
  • 23
  • 31
  • 3
    You mean you have replace [alert show];.....code with [alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];...right? – Navnath Memane Nov 05 '12 at 10:27
  • Its not working for me. I have also the same problem above. can you suggest or should I place one question for this? – Navnath Memane Nov 05 '12 at 11:09
  • @NavnathMemane : yes ...replace the [alert show]; ...in this case, it crash because the process might not perform in the main thread and the thread might be release by arc. Somehow, I am sure that this issue is about performing the action into the right and not nil thread. If you can show some more error or crash log we can take a look on it. – Arnlee Vizcayno Nov 05 '12 at 11:53