处理NSNotificationCenter通知导致bad_access

时间:2011-07-05 09:58:11

标签: nstimer uiwindow nsnotificationcenter

我正在为我的应用程序的UIWindow创建子类,然后当用户没有活动时,我使用NSNotificationCenter发出通知。我在用 [NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:重复:]

我在AppDelegate类中处理这个问题。这工作正常,除非我使用MBProgressHUD运行代码 - http://iosdevelopertips.com/open-source/ios-open-source-heads-up-display-with-mbprogresshud.html  我认为开始另一个线程。当它的完成委托与响应通知的代码正在运行时同时触发时发生错误。我很确定这是一个线程问题,但我该如何避免这种情况

1 个答案:

答案 0 :(得分:0)

您可以在app delegate上使用@synchronized。由于app delegate是一个单身人士,你将需要由它保护的关键部分:一个在“完成委托”,另一个在你的app委托。

Apple线程文档中的更多信息here

编辑:this关于线程和通知的链接是您的良好信息来源。

编辑2:this one甚至更好