2

Ok guys, so I have a map view with annotations and when tapped, they display callouts with a disclosure icon on the right. When tapped, this function is called:

- (void)showDetails:(id)sender
{
    NSLog(@"showDetails: called!");
    NSLog(@"sender: %@",sender);
    PermitDetailViewController *permitDetail = [[PermitDetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
    NSLog(@"permitDetail.title: %@",permitDetail.title);
    permitDetail.title = sender.title; //compiler doesn't like this!
    NSLog(@"permitDetail.title: %@",permitDetail.title);
    [self.navigationController pushViewController:permitDetail animated:YES];
    [permitDetail release];
}

All well and good so far, but I need to know what the callout's title was. I am trying to do sender.title but that ain't working to well... Any ideas?

This is the console output when I change the problematic line to permitDetail.title = self.title;:

2010-12-02 11:50:06.044 Parking[55413:207] showDetails: called!
2010-12-02 11:50:06.045 Parking[55413:207] sender: <UIButton: 0x8139890; frame = (104 8; 29 31); opaque = NO; autoresize = LM; layer = <CALayer: 0x8139920>>
2010-12-02 11:50:06.045 Parking[55413:207] permitDetail.title: (null)
2010-12-02 11:50:06.045 Parking[55413:207] permitDetail.title: All Permits
Stunner
  • 12,025
  • 12
  • 86
  • 145

1 Answers1

8

The sender in your case is the callout button (not the MKAnnotation) so it doesn't have the title property.

In viewForAnnotation, remove the addTarget on the disclosure button. Just set the annotation view's rightCalloutAccessoryView to be the button.

Then implement the calloutAccessoryControlTapped delegate method which will be called when the callout is tapped. It also provides a reference to the annotation view in the call. The annotation view contains a reference to the annotation:

- (void)mapView:(MKMapView *)mapView 
        annotationView:(MKAnnotationView *)view 
        calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"callout annotation.title = %@", view.annotation.title);

    //do your show details thing here...
}
  • I am confused by this statement: "In viewForAnnotation, remove the addTarget on the disclosure button. Just set the annotation view's rightCalloutAccessoryView to be the button." It seems to me that you are suggesting that I get rid of the disclosure icon on the callout and just have it so that the user taps the callout to get to the detail view. I would really prefer having that disclosure icon there if at all possible. I still feel that I am not quite understanding everything you said, mind clearing it up for me a bit? Thanks. – Stunner Dec 02 '10 at 22:45
  • Nevermind... I figured it out. I got rid of the addButton... method: UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; annotationView.rightCalloutAccessoryView = rightButton; And then I implemented what you said to implement and it worked! You know your stuff dude, props! – Stunner Dec 02 '10 at 23:02
  • Thanks, glad it worked out. Sorry I wasn't clear. I meant remove the call to addTarget. You don't need to specify your own method to call on callout click because map view has a delegate for it. –  Dec 02 '10 at 23:08
  • Yeah, I realized that's what you meant after I tried it and it worked, haha. Thanks again! – Stunner Dec 03 '10 at 02:27