Reputation: 1478
I want to add action on tap on title of userLocation. So I try add rightCalloutAccessoryView but want to leave default marker. How can I do that?
- (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];
}
Upvotes: 0
Views: 123
Reputation: 3628
Use:
- (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
}
}
Updated answer:
- (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];
}
Upvotes: 1