2013-02-11 45 views
2

我的应用得到了崩溃,使输出如下:为什么我的代码崩溃了一些UIWebView异常?

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

很明显,您正在使用的WebView在来往打电话给你的方法后台线程 – 2013-02-11 13:37:19

+0

我没有在我的课堂上使用webview我解析XML数据并显示在文本 – 2013-02-11 13:39:31

+0

看看这里:http://stackoverflow.com/questions/9679754/tried-to-obtain-the-web-锁定线程以外的其他主线程或网页以解决类似问题的答案。您可能需要使用GCD或其他形式的回调,以避免从后台线程调用UIKit方法 – 2013-02-11 13:39:52

回答

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

,如果你要做到这一点,必须在主线程中完成任何UI操作..

简单地粘贴以下语法

内部编码
dispatch_sync(dispatch_get_main_queue(), ^{ 
    //Your code goes here 
}); 

,或者您可以使用下面的语法

[self performSelectorOnMainThread:@selector(yourmethod:)withObject:obj waitUntilDone:YES] 
相关问题