2012-06-18 39 views
0

我创建右附件按钮注释标注,使用下面的代码如何跟踪哪些注释标注点击

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 

if ([annotation isKindOfClass:[MKUserLocation class]]){ 
    return nil; 
} 

else { 

    static NSString *AnnotationViewID = @"annotationViewID"; 

    MKAnnotationView *annotationView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; 

    if (annotationView == nil) 
    { 
     annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID]; 
    } 

    annotationView.image = [UIImage imageNamed:@"Mevents.png"]; 
    annotationView.annotation = annotation; 
    annotationView.canShowCallout=YES; 

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [rightButton setTitle:annotation.title forState:UIControlStateNormal]; 
    [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside]; 

    annotationView.rightCalloutAccessoryView = rightButton; 

    // UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]]; 
    // pinView.leftCalloutAccessoryView = profileIconView; 
    // [profileIconView release]; 

    return annotationView; 

} 

} 

如何跟踪,其注释点击?我想加载详细信息屏幕ID并获取基于该ID的数据以显示信息。

回答

0

当您创建注释中viewForAnnotation标签添加到它

annotationView.image = [UIImage imageNamed:@"Mevents.png"]; 
//Add this after 
annotationView.tag = 111; 

现在,检查此标签

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 

if ([annotation isKindOfClass:[MKUserLocation class]]){ 
    return nil; 

    if(annotation.tag == 111) 
     //Do something 
    else 
     //Do some other thing 
}