2010-12-30 5 views
1

showdetails를 보내는 주석을 찾는 방법은 무엇입니까?showdetails를 보내는 주석을 찾는 방법은 무엇입니까?

MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:BridgeAnnotationIdentifier] autorelease]; 
      customPinView.pinColor = MKPinAnnotationColorPurple; 
      customPinView.animatesDrop = YES; 
      customPinView.canShowCallout = YES; 

      // add a detail disclosure button to the callout which will open a new view controller page 
      // 
      // note: you can assign a specific call out accessory view, or as MKMapViewDelegate you can implement: 
      // - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control; 
      // 
      UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
      [rightButton addTarget:self 
          action:@selector(showDetails:) 
        forControlEvents:UIControlEventTouchUpInside]; 
      customPinView.rightCalloutAccessoryView = rightButton; 

      return customPinView; 

- (void)showDetails:(id)sender 
{ 
    some code 
} 

답변

8

코드에 주석이 있습니다. 사용자 정의 메서드를 사용하고 addTarget을 호출하는 대신지도 뷰의 calloutAccessoryControlTapped 대리자 메서드를 사용합니다. 이 방법에서는 주석에 대한 참조가 포함 된 주석보기에 대한 참조를 가져옵니다.

addTarget을에 전화를 제거하여 "showDetails"방법을 대체 :

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
    calloutAccessoryControlTapped:(UIControl *)control 
{ 
    MyAnnotationClass *annot = (MyAnnotationClass *)view.annotation; 
    //do something... 
} 
+0

을하지만 그는 하나를 클릭 한 많은 주석들 알고 싶어! – carbonr

+0

@ carbonr,'view.annotation'은 클릭 한 것입니다. addTarget 대신 delegate 메서드를 사용하는 것이 좋습니다. – Anna

+0

@ carbonr 위임자 대신 addTarget을 사용해야하거나 사용하려는 경우이 답변을 참조하십시오. http://stackoverflow.com/a/9876255/467105 – Anna

관련 문제