I am adding a button to annotation callout. On click event of button, I want to push another View Controller with details of annotation like title and subtitle. However, the problem is I am not able to get these details.
Here's what I did so far:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)userannotation
{
if ([annotation isMemberOfClass:[MKUserLocation class]])
{
return nil;
}
MKPinAnnotationView *v =[[MKPinAnnotationView alloc] initWithAnnotation:userannotation reuseIdentifier:@"ku"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
button.frame = CGRectMake(0, 0, 24, 24);
// [button addTarget:self action:@selector(callOutPressed:) forControlEvents:UIControlEventTouchUpInside];
v.rightCalloutAccessoryView = button;
v.canShowCallout = YES;
return v;
}
/*
- (void) callOutPressed:(id)sender
{
[ dict setValue:annotation.subtitle forKey:@"jid"] ;
[dict setValue:annotation.title forKey:@"name"];
NSLog(@"annotation values - %@",dict); // this shows null
*/
Okay. I tried using this:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"display name :-%@", view.annotation.title);// shows name
[dict setValue:view.annotation.title forKey:@"name"];//dict shows 0 key/value pairs and the app crashes.
NSLog(@"output :-%@", dict); //shows null
}
What is the correct way to do it?