从后台线程显示的UIAlertView没有委托创建EXC_BAD_ACCESS [英] UIAlertView shown from background thread and with no delegate creates EXC_BAD_ACCESS

查看:76
本文介绍了从后台线程显示的UIAlertView没有委托创建EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

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

此代码在后台线程中执行(负责解析),以及错误只会每隔一段时间发生一次。关于这里有什么问题的任何想法?

This code is executed in a background thread (responsible for parsing), and the error only happens every other time. Any idea on what is the problem here?

推荐答案

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

Dont mess with the UI from the background thread. Create a method and call that method on the main thread:

[someObject performSelectorOnMainThread:@selector(showDebug:)
                             withObject:@"JSON Parsing Error"
                          waitUntilDone:YES];

这篇关于从后台线程显示的UIAlertView没有委托创建EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆