0

I want to display quite a bit of demographic data for a certain pin when someone touches on it, so providing a pop-up isn't going to cut it. I figured once the pin is touched I will just stick a tableviewController onto the NavigationController and the table view will have access to the object and display the single objects information, with one item per row and 1 section.

Anyway I'm having a hard time figuring out MKMapViewDelegates methods as it appears none of them do what I need and/or allow me to return a tableview or push that view onto the navigation controller.

I played around with:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;   

But that requires a MKAnnotationView be returned and I really just need this method to work by showing the user a table view of all the data. I was hoping for something simple like a userDidTouchPin method....

Anyone have any ideas how to accomplish what I am trying to do?

Justin
  • 859
  • 4
  • 15
  • 30

1 Answers1

2

If you want to do something when the user selects the pin (and not a button on its callout), then implement the mapView:didSelectAnnotationView: delegate method and present or push your detail view controller there.

The selected annotation object is available as the annotation property of the view parameter:

- (void)mapView:(MKMapView *)mapView 
    didSelectAnnotationView:(MKAnnotationView *)view
{   
    YourDetailViewController *dvc = [[YourDetailViewController alloc] init...
    dvc.annotation = view.annotation;
    //present or push here
    [dvc release];
}

You might need to check which type of annotation was selected (eg. if MKUserLocation was selected do nothing, etc) and you might need to cast the view.annotation to your own annotation class to easily access any custom properties you may have.

  • Thank you kindly! Not sure why I missed "selecting annotation views" section in the documentation! I'm not sure you want to release the controller though, is that not handled by the NavigationController? I asked because I've done 'release' on that before and it's caused problems. – Justin Jul 14 '11 at 11:34
  • Unless you're using ARC or doing `autorelease` on the alloc+init line, you do [need to `release`](http://developer.apple.com/library/ios/#DOCUMENTATION/General/Conceptual/DevPedia-CocoaCore/MemoryManagement.html). If that gives problems, there may be other issues within the view controller being presented. May want to ask another question about it and include any error messages and stack trace. –  Jul 14 '11 at 12:26