从主线程或Web线程以外的线程获取Web锁定。不应该从辅助线程调用UIKit

时间:2013-05-02 05:15:35

标签: iphone ios ipad

我收到错误

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

代码NSString *tokenString=[NSString stringWithFormat:@"username=%@&password=%@",[[userName.text lowercaseString] MD5],[password.text MD5]];

我正在使用类文件来代替MD5。我是从MD5

得到的

导致线程锁定的md5如何删除此警告

4 个答案:

答案 0 :(得分:2)

当您从辅助线程调用UIKit时会发生这种情况......

要解决此问题,请尝试以下

dispatch_sync(dispatch_get_main_queue(), ^{

//Call the function from here

});

[self performSelectorOnMainThread:@selector(yourmethod:)withObject:obj waitUntilDone:YES]

答案 1 :(得分:1)

为避免崩溃,请使用此函数在主线程上调用方法

希望,这将是您的问题的解决方案。

[self performSelectorOnMainThread:@selector(doneButtonAction) withObject:nil waitUntilDone:NO];

答案 2 :(得分:0)

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

修复在概念上很简单;不要从辅助线程更新UI。通过调用performSelectorOnMainThread方法更新主线程中的UI

答案 3 :(得分:0)

类似的问题已经得到解答here is the link to it 只需使用

dispatch_async(dispatch_get_main_queue(), ^{      });

获取密码和用户名时,

希望这能解决您的问题