2014-02-12 2 views
0

주석을 UITapGestureRecognizer로 연결합니다. 나는 터치를 감지하고 싶다.보낸 사람을 통해 특수 효과에 대한 참조를 얻는 방법은 무엇입니까?

if ([annotation isKindOfClass:[Annotation class]]) 
{ 
    NSString * annotationIdentifier = @"UserAnnotationIdentifier"; 
    CustomAnnotationView * customAnnotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier]; 
    if (!customAnnotationView) 
    { 
     customAnnotationView = [[CustomAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationIdentifier]; 
     UITapGestureRecognizer *tapGesture = 
     [[UITapGestureRecognizer alloc] initWithTarget:self 
               action:@selector(calloutTapped:)]; 
     [customAnnotationView addGestureRecognizer:tapGesture]; 

나는 코드의 바닥을 사용하지만, 그것은

-(void) calloutTapped:(id) sender { 
     id<MKAnnotation> annotation = ((MKAnnotationView*)sender.view).annotation; 

ERROR 컴파일에서 오류가 발생 : 속성보기는 유형 __strong ID의 객체를 찾을 수 없습니다

답변

0

변경 :

-(void) calloutTapped:(id) sender 

대상 :

다음 senderview 재산 또는 먼저 캐스팅 senderUITapGestureRecognizer에있을 것입니다.
가 제대로 캐스트하려면

-(void) calloutTapped:(id) sender { 
    UITapGestureRecognizer *tapGesture = (UITapGestureRecognizer *)sender; 
    MKAnnotationView *sendersView = (MKAnnotationView *)tapGesture.view; 
    id<MKAnnotation> annotation = sendersView.annotation; 
} 
+1

덕분에, 당신은 내 일 만들기! 잠시 후 대답을 수락합니다. – user3300062

+0

보낸 사람을 UITapGestureRecognizer로 캐스팅하려면 어떻게해야합니까? 보낸 사람 = (UITapGestureRecognizer *) 보낸 사람; 작동하지 않음 – user3300062

+0

각 항목의 전송에 대한 내 답변이 업데이트되었습니다. 주석 뷰의 'tag'속성을 설정하여 식별 할 수 있고 여러 탭 동작에 대해이 메소드를 재사용 할 수 있습니다. 그냥 생각. – graver

관련 문제