Exc_Bad_Access in alertview

Receive Exc_Bad_Access in the UIAlertView message.

UIAlertView *systemAlert1 = [[UIAlertView alloc]initWithTitle:@"System message" message:@"note" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [systemAlert1 show]; **//Crashing on this line [EXC_BAD_ACCESS]** [systemAlert1 release]; 

Why am I getting this? Please, help

+1
objective-c iphone xcode crash exc-bad-access
source share
2 answers

ANY UI stuff, including showing alerts, must be run in the main thread. If you do this in some other thread, this will definitely work.

+1
source share

Perhaps this is due to the fact that your warning is being called from the background thread, and not from the main thread. It is recommended that changes related to the user interface should only be made on the main topic in order to avoid this behavior of the application.

Try this code:

 UIAlertView *systemAlert1 = [[UIAlertView alloc]initWithTitle:@"System message" message:@"note" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [systemAlert1 performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES]; [systemAlert1 release]; 

Hope this helps. Let me know if you need anything else.

0
source share

All Articles