从后台线程显示的UIAlertView没有委托创建EXC_BAD_ACCESS

Dir*_*nry 9 exc-bad-access uialertview ios

这是我的代码:

#ifdef DEBUG
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"JSON Parsing Error" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];
#endif
Run Code Online (Sandbox Code Playgroud)

此代码在后台线程中执行(负责解析),并且错误仅在每隔一次发生.有什么问题在这里有什么想法吗?

Ser*_*ura 17

不要在后台线程中弄乱UI.创建一个方法并在主线程上调用该方法:

[someObject performSelectorOnMainThread:@selector(showDebug:)
                             withObject:@"JSON Parsing Error"
                          waitUntilDone:YES];
Run Code Online (Sandbox Code Playgroud)