在UIAlertView显示消息中获取Exc_Bad_Access。
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];
为什么我会这样?请帮忙
答案 0 :(得分:1)
任何UI内容,包括警报的显示都应在主线程上完成。 如果你在其他线程上执行此操作,它肯定会崩溃。
答案 1 :(得分:0)
可能是因为您的警报是从后台线程而不是主线程调用的。建议仅在主线程上进行与用户界面相关的更改,以避免应用程序的这种行为
试试这段代码:
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];
希望这会有所帮助。如果您还有其他需要,请告诉我。