2013-02-11 61 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] 
相關問題