我的应用程序崩溃并提供如下输出:
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
任何人都可以让我知道,我忘记了,我不知道这里发生了什么
答案 0 :(得分: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
});
});
答案 1 :(得分:1)
如果您要进行任何UI操作,则必须在主线程上完成..
只需将编码粘贴在以下语法
中dispatch_sync(dispatch_get_main_queue(), ^{
//Your code goes here
});
或者您可以使用以下语法调用您的方法
[self performSelectorOnMainThread:@selector(yourmethod:)withObject:obj waitUntilDone:YES]