2012-08-17 4 views
0

위해 나는 다음과 같이 수행합니다 SEGUE 있습니다. 내가하는 일은 서버에 대한 원격 호출을하는 것이고, 서버 응답이 올바르게 돌아 오면, 나는 그 segue를 가진 새로운 페이지로 사용자를 데려다려고한다.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]; 
     }]; 
    } 
} 
+0

서버에 대한 원격 호출을 어떻게 처리합니까? 비동기 호출이고 주 스레드가 아닌 웹 서비스를 호출하는 스레드에서 segue하려고하면이 문제가 발생할 수 있습니다. 아마도 좀 더 많은 코드를 게시 할 수 있습니까? 요청이 중단되고 segue가 수행되는 전체 기능이 있습니까? –

+0

@Paul 예, 비동기 호출을 수행하고 리턴 코드에서 segue를 시도합니다. 이 오류가 발생하지 않도록이 작업을 수행하는 올바른 방법은 무엇입니까? ... 지금 코드 게시 중 ... – GeekedOut

+0

@Paul 방금 사용한 코드 중 일부를 추가했습니다 ... 많은 오류 검사 및 기타 논리를 수행했지만, 내가하는 일은 요주의입니다. – GeekedOut

답변

2

때 UI를 터치 방법 거랑를 수행 할 때, 당신이 메인 스레드에서 해당 코드를 호출하고 있는지 확인하는 것이 중요하다 등. 그것을 조금 우회입니다

[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 performSelectorOnMainThread:@selector(performPlanToBusinessSegueOnMainThread) 
          withObject:nil 
         waitUntilDone:YES]; 
}]; 

을 :하지만,이 같은 완성 된 블록이 메서드를 호출 할 수 있습니다, 그리고

- (void)performPlanToBusinessSegueOnMainThread 
{ 
    [self performSegueWithIdentifier:@"PlanToBusiness" sender:self]; 
} 

: 그 작업을 수행하는 가장 쉬운 방법은이 같은 방법을 확인하는 것입니다 예외를 수정해야합니다. performSelectorOnMainThread 메서드에서 performSegueWithIdentifier을 호출 할 수 있으면 좋지만 인수가 너무 많습니다.

+0

스마트! 나는 네가하는 일을 본다. 그래서 서버에서 돌아 오는 코드의 맨 마지막에 함수를 호출해야합니다. 그런 식으로이 스레드가 실행을 중지하도록 보장합니까? – GeekedOut

+0

'waituUntilDone' 인수를'Yes'로 설정해두면 원하는 곳이라면 어디든지 놓을 수 있어야하고 다른 스레드에서 전혀 호출되지 않는 것처럼 거의 똑같이 실행됩니다 (예외 사실 예외가 발생하지는 않을 것입니다!) 단지 웹 스레드가'performSelectorOnMainThread' 함수가 다음 줄로 갈 때까지 돌아올 때까지 대기하게됩니다. –

+0

감사합니다! :) 매우 감사. – GeekedOut

관련 문제