0

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?

Garrett Hyde
  • 5,409
  • 8
  • 49
  • 55
iCodes
  • 1,382
  • 3
  • 21
  • 47
  • What is your problem exactly? You don't know how to push a new viewController? – Franck Nov 29 '13 at 15:10
  • @Franck, he can't pass annotation to callOutPressed action – NeverBe Nov 29 '13 at 15:11
  • i need the details like title and subtitle of annotations – iCodes Nov 29 '13 at 15:11
  • @icodes, add to button's tag an object index, then use this index to obtain your object from array as example. – NeverBe Nov 29 '13 at 15:12
  • 2
    See http://stackoverflow.com/questions/9876042/annotation-details-after-detail-disclosure-pressed, http://stackoverflow.com/questions/9462699/how-to-recognize-which-pin-was-tapped, http://stackoverflow.com/questions/9097469/how-to-connect-map-annotation-view-buttons-with-database-to-go-to-another-view, http://stackoverflow.com/questions/4565197/how-to-find-which-annotation-send-showdetails, http://stackoverflow.com/questions/16825496/how-to-call-a-segue-from-a-disclosure-button-on-a-map-pin, etc. –  Nov 29 '13 at 15:15
  • I don't recommend using a button tag. There are much better ways in the links provided. –  Nov 29 '13 at 15:17
  • Have you tried logging `view.annotation.title` instead of `annotation.title`? Don't know what the `annotation` variable is but it has nothing to do with `view.annotation`. –  Nov 29 '13 at 15:42
  • Thanx that helped, but still i cant copy the name...into dictionary – iCodes Nov 29 '13 at 16:10

0 Answers0