2

我的应用程序崩溃并提供如下输出:

Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
1   WebThreadLock
2   -[UIWebDocumentView(UIWebDocumentViewTextSelecting) selectionBaseWritingDirection]
3   -[UITextField _resignFirstResponder]
4   -[UIResponder _finishResignFirstResponder]
5   -[UIResponder resignFirstResponder]
6   -[UITextField resignFirstResponder]
7   -[UIView(UITextField) endEditing:]
8   -[UIWindowController _prepareKeyboardForTransition:fromView:]
9   -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
10  -[UIViewController presentViewController:withTransition:completion:]
11  -[UIViewController presentViewController:animated:completion:]
12  -[UIViewController presentModalViewController:animated:]
13  -[studentlogViewController parse]
14  -[NSThread main]
15  __NSThread__main__
16  _pthread_start
17  thread_start

谁能告诉我,我疯了,我不知道这里发生了什么

4

2 回答 2

2

您在后台解析一些数据(这很好),然后从后台线程更新 UI,这是错误的。您必须从主线程更新 UI:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    [studentLogViewController parse];
    dispatch_async(dispatch_get_main_queue(), ^{
        // now present the new view controller
    });
});
于 2013-02-11T13:40:00.697 回答
1

如果您要执行任何 UI 操作,则必须在主线程上完成..

只需将编码粘贴到以下语法中

dispatch_sync(dispatch_get_main_queue(), ^{
    //Your code goes here
});

或者您可以使用以下语法调用您的方法

[self performSelectorOnMainThread:@selector(yourmethod:)withObject:obj waitUntilDone:YES]
于 2014-05-05T13:16:00.970 回答