关于在访问文本字段时从其他线程获取锁的警告 [英] Warning about obtaining lock from other thread when accessing text field

查看:65
本文介绍了关于在访问文本字段时从其他线程获取锁的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为_passwordTextFieldUITextField,在其中隐藏了输入内容:

I have a UITextField named _passwordTextField, where I'm hiding the input:

[_passwordTextField  setSecureTextEntry:YES]; 

每次我使用passwordTextField.text访问该字段的文本时,都会看到此警告:

every time I access the field's text with passwordTextField.text, I see this warning:

void _WebThreadLockFromAnyThread(bool),0x9077460:从除主线程或Web线程之外的其他线程获取Web锁.不应从辅助线程调用UIKit.

void _WebThreadLockFromAnyThread(bool), 0x9077460: 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.

如何删除此警告?

推荐答案

这与UITextField无关. iOS UIKit要求在主线程&上完成对UI的任何直接操作.不是来自后台线程.

This has nothing to do with UITextField. iOS UIKit requires any direct manipulation to UI to be done on main thread & not from background thread.

如果执行此操作,则您的应用程序将不稳定,甚至在某些情况下可能会崩溃.因此,请不要从后台线程更新UIKit元素.请检查您的代码.

If you are doing this, your app will be unstable and in some situations might even crash. So as a rule do not update UIKit elements from background thread. Please inspect your code.

如果您使用的是iOS> = 4,则可以使用

If you're using iOS >= 4, you can use GCD do this instead:

dispatch_async(dispatch_get_main_queue(), ^{
    [self doSomething:1 b:2 c:3 d:4 e:5]; //changes UI method
});

更新:请再次检查您的代码.在处理线程问题时,您不必注意该警告发生在哪一行,而是需要整体查看.看看是从主线程还是后台线程调用整个方法.

UPDATE: please check your code again. when dealing with threading issues, its not which line this warning occurs you need to observe but you need to see in its entirety. See if the entire method is getting called from main thread or background thread..

这篇关于关于在访问文本字段时从其他线程获取锁的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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