EXC_BAD_ACCESS on UIAlertview code=1

故事扮演 提交于 2019-12-22 04:33:27

问题


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

回答1:


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....




回答2:


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

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



来源:https://stackoverflow.com/questions/13176253/exc-bad-access-on-uialertview-code-1

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