问题
I have a UITextField
named _passwordTextField
, where I'm hiding the input:
[_passwordTextField setSecureTextEntry:YES];
every time I access the field's text with passwordTextField.text
, I see this warning:
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.
How do I remove this warning?
回答1:
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.
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.
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..
来源:https://stackoverflow.com/questions/14207483/warning-about-obtaining-lock-from-other-thread-when-accessing-text-field