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 に答える