2012-09-26 5 views
0

드래그하면 mkannotationview의 제목을 변경하고 싶습니다. MKannotationview에는 title 속성이 없습니다. 사용자 정의보기가 있습니다. 어떻게 dragstate 대리자 메서드에서 액세스 할 수 있습니까?드래그 된 mkannotationview의 제목을 변경하는 방법

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
    didChangeDragState:(MKAnnotationViewDragState)newState fromOldState: 
    (MKAnnotationViewDragState)oldState 
    { 
    NSLog(@"old state, new state:%d, %d",oldState,newState); 
    //view setTitle 
    } 

여기에서 viewforannotationdelegate 메소드를 호출 할 수 있다면 도움이 될 것입니다. 그래서 적어도 가능합니까?

답변

2

이 올바른 캐스팅이다

   ParkPlaceMark *annotation = (ParkPlaceMark *)view.annotation; 

장소 표시 - 내 사용자 정의 클래스; 뷰 - mkannotationview 제어 절대 루프 내부 않을된다

+0

@bbodayle : 아이디어를주는 고맙습니다. –

0

MKAnnotationView은 title 속성이 포함 된 고유 한 하위 클래스로 캐스팅 할 수 있습니다.

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

    if([view isKindOfClass:[CustomMKAnnotationView class]]) { 
     CustomMKAnnotation *customView = (CustomMKAnnotation *)view.annotation; 
     customView.title = @"New Title"; 

    } 
} 
+0

: - (무효)지도보기 (MKMapView *)지도보기 annotationView : (MKAnnotationView *) 뷰 didChangeDragState : (MKAnnotationViewDragState) newState fromOldState : (MKAnnotationViewDragState) oldState { if ([view isKindOfClass : [ParkPlaceMark class]]) { ParkPlaceMark * customView = (ParkPlaceMark *) view; customView.title = @ "POI"; }} –

+0

- (MKAnnotationView *)지도보기 (MKMapView *)지도 viewForAnnotation (ParkPlaceMark *) 주석 { MKAnnotationView 시험 * = [MKAnnotationView ALLOC] initWithAnnotation : 주석 reuseIdentifier @ "parkingloc"]; \t if ([annotation.title caseInsensitiveCompare : @ "POI"] == NSOrderedSame) \t { test.annotation = annotation; test.userInteractionEnabled = YES; test.draggable = YES; [주석 ​​세트 제목 : @ "새 제목"]; [test setEnabled : YES]; [test setCanShowCallout : YES]; \t} –

+0

나는 솔루션에서 아이디어를 가지고 -하지만 당신은 그것을 완료 할 것이다 - ParkPlaceMark * 공원 = [[ParkPlaceMark ALLOC] initWithAnnotation :보기 reuseIdentifier : @ "parkingloc"]; mkannotationview에 init park의 주요 개체 자체를 어떻게 초기화합니까? 이미 존재하는 것과 같은 예시 : parkplacemark.h에서 : @interface의 ParkPlaceMark : NSObject의 {...} placemark.m에 : - (ID) initWithTitle (는 NSString *) ttl andCoordinate : (CLLocationCoordinate2D) c2d { \t [super init]; \t title = ttl; \t 좌표 = c2d; \t return self; } –

관련 문제