gpt4 book ai didi

ios - WebThreadLock 与 setCompletionBlock 中的 PerformSegue (ASIHTTPRequest)

转载 作者:行者123 更新时间:2023-11-29 04:52:38 25 4
gpt4 key购买 nike

尝试在 ASIHTTPRequest 请求的 setCompletionBlock 内执行 PerformSegueWithIdentifier 方法时遇到错误。

这是一些代码(省略了某些部分):

// 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

从这个错误中,我假设它与我仍在使用网络线程或其他东西时尝试进入新的 View Controller 这一事实有关。我还是 iOS 开发新手,所以不太确定。任何帮助将不胜感激。

最佳答案

事实上,您可以在此处从 UI(主)线程以外的线程修改 UI:

[self performSegueWithIdentifier:@"ShowTitles" sender:self];

您需要在主线程上执行它。您可以使用performSelectorOnMainThread来做到这一点.

关于ios - WebThreadLock 与 setCompletionBlock 中的 PerformSegue (ASIHTTPRequest),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8567963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com