1

NSManagedObjectのサブクラス "Location"があり、このクラスはMKAnnotationに準拠しています。ピンをドラッグしてMKMapViewのジオコーディングを逆にする

マップに場所を追加すると、ReverseGeocoderが起動します。コールアウトに表示されているピンをクリックすると、ピンのアドレスが表示されます。だからすべてうまく動作します。

今、私の問題です。

私はピンをドラッグすることができます。ドラッグが終了すると、ReverseGeocoderが再び位置データを要求し始めます。しかし、PlacemarkはLocationオブジェクトで更新されますが、コールアウトビューにはまだ古いアドレスがあります。もう一度ドラッグすると、新しい住所が表示されます。 (私がドラッグしたので、新しいものはもはや新しいものではない)。すべてのヘルプは素晴らしいだろう、私は逆ジオコーダデリゲート

- (void)reverseGeocoder:(MKReverseGeocoder*)geocoder didFindPlacemark:(MKPlacemark*)place 
{ 
    Location* theAnnotation = [self.map annotationForCoordinate:place.coordinate]; 
    if (!theAnnotation) 
     return; 
    // Associate the placemark with the annotation. 
    theAnnotation.city = [place locality]; 
    theAnnotation.zipcode = [place postalCode]; 
    theAnnotation.street = [place thoroughfare]; 

    DEBUGLOG(@"Place: %@", place); 


    // Add a More Info button to the annotation's view. 
    MKPinAnnotationView* view = (MKPinAnnotationView*)[self.map viewForAnnotation:theAnnotation]; 
    if (view) 
    { 
     DEBUGLOG(@"SUBTITLE: %@", theAnnotation.subtitle); 
     view.leftCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

    } 
} 

ため

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState{ 

//if dragging ended 
if (newState == MKAnnotationViewDragStateNone && oldState == MKAnnotationViewDragStateEnding) { 

    CLLocation *location = [[CLLocation alloc] initWithLatitude:annotationView.annotation.coordinate.latitude longitude:annotationView.annotation.coordinate.longitude]; 
    [self geocodeLocation:location forAnnotation:annotationView.annotation]; 
    [location release]; 
} 

とコード:ここで

は、ドラッグ状態のために私のコードです。最終的には、地図アプリケーションをドラッグすることで最も効果的な例です。

答えて

2

私は考えました。

KVOのため、私はLocationオブジェクトのサブタイトルを設定する必要があります。だからそれは表示されます。 subtilteが

// Associate the placemark with the annotation. 
theAnnotation.city = [place locality]; 
theAnnotation.zipcode = [place postalCode]; 
theAnnotation.street = [place thoroughfare]; 

によって生成されるため、

は、しかし、私はちょうど私のNSManagedObjectサブクラスで次の操作を実行しなければなりませんでした。

- (void) setSubtitle:(NSString *)title{ //do nothing} 
関連する問題