2012-11-06 4 views
0

내가 잠금 또는 파견 그룹과 함께 할 수있는 그 무언가를 알고 있지만 난 그냥 캔트를 코딩하는 것를 ... 대기 할 수있는 방법 방법을 떠나기 전에. 현재 스레드가 단지 오버런하여 TRUE를 반환합니다. 나는 자물쇠를 시도했다, dispatchers는 일하고 그러나 그것을 맞은 것처럼 보일 수 없다. 어떤 도움을 주시면 감사 :나는 geocodeAddressString에서 결과를 주소가 유효한 주소 인 경우 <p></p> 내가 알 필요가 아이폰

- (BOOL) checkAddressIsReal 
{ 
    __block BOOL result = TRUE; 

    // Lets Build the address 
    NSString *location = [NSString stringWithFormat:@" %@ %@, %@, %@, %@", streetNumberText.text, streetNameText.text, townNameText.text, cityNameText.text, countryNameText.text]; 

    // Put a pin on it if it is valid 

    CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
    [geocoder geocodeAddressString:location 
       completionHandler:^(NSArray* placemarks, NSError* error) { 
     result = [placemarks count] != 0; 
    }]; 

    return result; 
} 

답변

0

문서는 CLGeocoder 메인 스레드에서 completionHandler 호출하는 것을 말한다. 주 스레드에서 메서드를 호출 할 것이므로 결과를 전달할 기회를주지 않고 지오 코더의 응답을 기다릴 수 없습니다.

일부 API를 -[NSRunLoop runMode:beforeDate:]으로 사용하여 런 루프를 폴링하면됩니다.

단점은 모드에 따라 결과를 기다리는 동안 이벤트 및 화재 타이머도 전달된다는 것입니다.

+0

안녕하세요 당신이 마지막에이 문제를 해결 않았다, 내가 같은 문제가 있습니다. – HernandoZ

+0

Nope 미안하지만 내 코드가 조정되어 문제가되지 않았습니다. – Aardvark

0

그냥 매개 변수로 블록을 사용

- (void) checkAddressIsRealWithComplectionHandler:(void (^)(BOOL result))complectionHandler 
{ 
    __block BOOL result = TRUE; 

    // Lets Build the address 
    NSString *location = [NSString stringWithFormat:@" %@ %@, %@, %@, %@", streetNumberText.text, streetNameText.text, townNameText.text, cityNameText.text, countryNameText.text]; 

    // Put a pin on it if it is valid 

    CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
    [geocoder geocodeAddressString:location 
       completionHandler:^(NSArray* placemarks, NSError* error) { 
        result = [placemarks count] != 0; 
        complectionHandler(result); 
       }]; 
}