gpt4 book ai didi

ios - 关于访问文本字段时从其他线程获取锁的警告

转载 作者:行者123 更新时间:2023-11-28 20:25:22 26 4
gpt4 key购买 nike

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

[_passwordTextField  setSecureTextEntry:YES]; 

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

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 的任何直接操作都在主线程上完成,而不是从后台线程完成。

如果您这样做,您的应用将不稳定,在某些情况下甚至可能崩溃。因此,规则是不要从后台线程更新 UIKit 元素。请检查您的代码。

如果您使用的是 iOS >= 4,您可以使用 GCD改为这样做:

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

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

关于ios - 关于访问文本字段时从其他线程获取锁的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14207483/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com