我有一个赛格瑞,我这样做:错误模拟器为iPad而不是iPhone
[self performSegueWithIdentifier:@"PlanToBusiness" sender:self];
它工作于iPhone,但不是在iPad上。我所做的是远程调用服务器,当服务器响应正确返回时,我尝试将用户带到具有该segue的新页面。
它适用于iPhone模拟器,但不是在iPad(识别字符串是两个相同),并在iPad上也与此错误崩溃:
bool _WebTryThreadLock(bool), 0x68f9cb0: 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 -[UINavigationController navigationTransitionView:didStartTransition:]
10 -[UINavigationTransitionView transition:fromView:toView:]
11 -[UINavigationTransitionView transition:toView:]
12 -[UINavigationController _startTransition:fromViewController:toViewController:]
13 -[UINavigationController _startDeferredTransitionIfNeeded]
14 -[UINavigationController pushViewController:transition:forceImmediate:]
15 -[UINavigationController pushViewController:animated:]
16 -[UIStoryboardPushSegue perform]
17 -[UIStoryboardSegueTemplate perform:]
18 -[UIViewController performSegueWithIdentifier:sender:]
19 __41-[PlanBusinessController submitBusiness:]_block_invoke_0
20 __block_global_0
21 -[NSBlockOperation main]
22 -[__NSOperationInternal start]
23 -[NSOperation start]
24 __block_global_6
25 _dispatch_call_block_and_release
26 _dispatch_worker_thread2
27 _pthread_wqthread
28 start_wqthread
我也不太习惯阅读O -ctive-C栈跟踪,所以我很难找出问题所在。
这是我如何做到这一点:
- (IBAction)submitBusiness:(id)sender
{
// Make a url to send
NSURL *url = [NSURL URLWithString:full_encoded_url_string];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
// ***************
// TODO: ok I dont really understand what this is
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
// **************
[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
// I took out a lot of the logic code that is not needed
[self performSegueWithIdentifier:@"PlanToBusiness" sender:self];
}];
}
}
你如何处理远程调用服务器?如果它是一个异步调用,并且您尝试在调用Web服务而不是主线程的线程中继续执行,则可能导致此问题。你可能会发布更多的代码,请求消失的地方以及执行segue的全部函数? – 2012-08-17 16:51:39
@Paul是的,我正在做一个异步调用,并尝试从返回代码继承。什么是正确的方式来做到这一点,以避免这种错误发生? ...现在发布代码... – GeekedOut 2012-08-17 16:53:26
@Paul我只是添加了一些我使用的代码...我拿出了很多错误检查和其他逻辑,但我做的是在那里。 – GeekedOut 2012-08-17 17:00:24