2013-03-14 42 views
0
void _WebThreadLockFromAnyThread(bool), 0x205acdf0: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread. 

这看起来很严重。我希望程序在那个时候打破。我不觉得我从主线外的任何地方访问UIKit。如何调试从主线程以外的线程获取Web锁定?

但是,警告就在那里,我不知道在我的代码出现这种情况

回答

2

这意味着你的代码是从非主线程在某个时刻调用。问题是你不记得或不知道在哪里。你只是觉得你没有,但实际上你的代码确实如此。

我的建议是沉重的动态断言。每个可疑的方法和功能安装线程检查断言。例如,

- (void)test 
{ 
    NSAssert([[NSThread currentThread] isMainThread], @"This code is expected to be called from main thread!"); 
} 

然后,断言最终会使您的应用程序在无效线程上下文中崩溃。如果你不那么幸运,你可以按照字面的方法在每个方法上安装断言。

无论如何,一旦你断言失败,你可以在那里开始。如果你发现不好的地方,下面的步骤只是微不足道的。

+0

这是最好的答案太远了:)我实际上已经找到问题所在。但是,我认为我们都需要更合理的东西。 – 2013-03-14 10:46:57

相关问题