【问题标题】: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从主线程或web线程以外的线程获取web lock。不应从辅助线程调用 UIKit
【发布时间】:2013-08-12 13:53:00
【问题描述】:

我收到一个错误

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 导致线程锁我怎样才能消除这个警告

【问题讨论】:

    标签: iphone ios ipad


    【解决方案1】:

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

    要解决这个问题,请尝试以下方法

    dispatch_sync(dispatch_get_main_queue(), ^{
    
    //Call the function from here
    
    });
    

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        【解决方案3】:
        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

        【讨论】:

        • 我编写了这样的代码__block NSString *tokenString; dispatch_sync(dispatch_get_main_queue(), ^{ tokenString=[NSString stringWithFormat:@"username=%@&password=%@",[[userName.text lowercaseString] MD5],[password.text MD5]]; }); 仍然无法正常工作。
        • 此代码与 UI 更新无关,您可以在其他地方更新 UI。
        • 我从安全类型文本字段中获取文本是否会导致问题?
        • 问题出在 userName.text 和 password.text,如果你在后台队列或线程中执行,请在主线程中提取 uitextfields 的文本。
        【解决方案4】:

        已经回答了类似的问题here is the link to it 只需使用

        dispatch_async(dispatch_get_main_queue(), ^{      });
        

        同时获取密码和用户名,

        希望这能解决您的问题

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-01-05
          • 2011-05-22
          • 1970-01-01
          相关资源
          最近更新 更多