Exc_Bad_Access in alertview show

浪子不回头ぞ 提交于 2019-12-24 11:24:44

问题


Getting Exc_Bad_Access in UIAlertView show 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 i am getting this?? Please help


回答1:


ANY UI stuff including the showing of alerts should be done on Main thread. If you are doing this on some other thread, it will definitely crash.




回答2:


It may be because your alert gets invoked from your background thread and not the main thread. It is recommended that user interface related changes should only be made on Main Thread to avoid this kind of behaviors 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.



来源:https://stackoverflow.com/questions/13084014/exc-bad-access-in-alertview-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!