Я получаю сообщение об ошибке при попытке выполнить метод performSegueWithIdentifier внутри setCompletionBlock запроса ASIHTTPRequest.WebThreadLock с performSegue в setCompletionBlock (ASIHTTPRequest)
Вот некоторый код (определенная часть была пропущена):
// Instantiate request object
ASIFormDataRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://[...]"]];
// Set request headers
[request addRequestHeader:@"Content-Type" value:@"application/json; charset=utf-8"];
// Format JSON request
NSString *json = [...]
// Set the post data
[request setPostBody:[[NSMutableData alloc] initWithData:[json dataUsingEncoding:NSASCIIStringEncoding]]];
__weak ASIFormDataRequest *_request = request;
// Handle success
[request setCompletionBlock:^{
// Get the response
NSDictionary *response = [[_request responseString] JSONValue];
// Do some stuff with the response...
// Show the title list
[self performSegueWithIdentifier:@"ShowTitles" sender:self];
}];
[request startAsynchronous];
Точная ошибка, я получаю:
bool _WebTryThreadLock(bool), 0x7d70520: 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 -[UITextRangeImpl isEmpty]
3 -[UITextRange(UITextSelectionAdditions) _isCaret]
4 -[UITextSelectionView setCaretBlinks:]
5 -[UIKeyboardImpl setCaretBlinks:]
6 -[UIKeyboardImpl setDelegate:force:]
7 -[UIKeyboardImpl setDelegate:]
8 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:]
9 -[UIResponder _finishResignFirstResponder]
10 -[UIResponder resignFirstResponder]
11 -[UITextField resignFirstResponder]
12 -[UIView(UITextField) endEditing:]
13 -[UIWindowController _prepareKeyboardForTransition:fromView:]
14 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
15 -[UIViewController presentViewController:withTransition:completion:]
16 -[UIViewController presentViewController:animated:completion:]
17 -[UIViewController presentModalViewController:animated:]
18 -[UIStoryboardModalSegue perform]
19 -[UIStoryboardSegueTemplate perform:]
20 -[UIViewController performSegueWithIdentifier:sender:]
21 -[BaseLoginViewController viewTitleList]
22 __39-[BaseLoginViewController getTitleList]_block_invoke_0
23 -[ASIHTTPRequest handleStreamComplete]
24 -[ASIHTTPRequest handleNetworkEvent:]
25 _signalEventSync
26 _cfstream_shared_signalEventSync
27 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
28 __CFRunLoopDoSources0
29 __CFRunLoopRun
30 CFRunLoopRunSpecific
31 CFRunLoopRun
Из этой ошибки я предполагаю, что это имеет какое-то отношение тот факт, что я пытаюсь перейти к новому контроллеру представления, пока я все еще использую веб-поток или что-то в этом роде. Я все еще новичок в iOS-разработчике, поэтому я не уверен. Любая помощь будет действительно оценена.
Отлично! Спасибо, спасибо. Именно поэтому я понимаю, какова фактическая причина, потому что вы не можете вносить изменения в пользовательский интерфейс, если вы не работаете в основном потоке, тогда как здесь я все еще работал в веб-потоке? У меня есть это правильно? – Sarah
@Sarah Точно. Это очень распространенное поведение во многих различных рамках, таких как java AWT и Android. – MByD