我有一个我喜欢这样的segue:
[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
我也不太习惯阅读 Obective-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];
}];
}
}