I want to add button in annotationView in mapkit in iphone for performing an action on clicking that button. How can i perform action on clicking that button? i also dont able to add button in annotation view using the following code:
- (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
Can anyone please tell me how can i add button to the default userlocation’s blue dot’s annotation view? Thanks in advance.
For adding the button in default blue dot’s annotationView, use the delegate method and add button there in following way: