开发者

Objective C, What is this warning?

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

I get this warning message if I try to get text from a UITextView.


Did you spawn another thread and call UIKit method from in it? Methods like + (void)detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget withObject:(id)anArgument or - (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg will spawn a new thread.

UI related codes should be used only in main thread. Because many of UI code uses multithreading heavily, so allowing of calling UI code from any thread easily cause unmanageable deadlock. So most of UI frameworks have this rule.

You can force a code to run in main thread by using method like - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait

As an example,

- (void)UIControlCode
{
}
- (void)processingCodeInOtherThread
{
    [self performSelectorOnMainThread:@selector(UIControlCode) withObject:nil waitUntilDone:NO];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜