点击 userLocation 的标题

Tap on title of userLocation

我想在点击 userLocation 的标题时添加操作。所以我尝试添加 rightCalloutAccessoryView 但想保留默认标记。 我该怎么做?

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

    if([annotation isKindOfClass:[MKUserLocation class]]){
        MKAnnotationView *annotationView = //What need I put here?
        annotationView.canShowCallout = YES;
        annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd];

    return annotationView;
}else {
    return nil;
}
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    [self performSegueWithIdentifier:@"DetailsIphone" sender:view];
}

使用:

   - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
      NSLog(@" we selected annotation");
      //self.mapView is your mapView ->
     if(view.annotation == self.mapView.userLocation)
     {
       // do your action here like [self method]; in your case->
     [self performSegueWithIdentifier:@"DetailsIphone" sender:view];  
     } 
       else {
     //no userlocation annotation was tapped ...another code  
     }
  }

更新的答案:

   - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
  NSLog(@" we selected annotation");
  //self.mapView is your mapView ->
 if(view.annotation == self.mapView.userLocation)
 {
   // do your action here like [self method]; in your case->
   UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(calloutTapped:)];
[view addGestureRecognizer:tapGesture];
 } 
   else {
   //no userlocation annotation was tapped ...another code  
   }
}


   -(void)calloutTapped:(UITapGestureRecognizer *) sender
{
    NSLog(@"Callout was tapped");
   [self performSegueWithIdentifier:@"DetailsIphone" sender:view];
 }