0

I have successfully used the Google Places API to display annotations on my map view. Now I'd like this information (name & address) to be sent to a detail view controller.

For now I only have a blank detail view controller with no information on it.

Here is the method with which I call the detail view controller:

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view   calloutAccessoryControlTapped:(UIControl *)control {
    id <MKAnnotation> annotation = [view annotation];
    if ([annotation isKindOfClass:[MapPoint class]])
    {
        NSLog(@"success");
    }
    [self performSegueWithIdentifier:@"ABC" sender:self];
}

And this is the method in which I try to "pass" the information to the detail view controller:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ABC"])
{
    MKAnnotationView *annotationView = sender;
    [segue.destinationViewController setAnnotation:annotationView.annotation];
}
}

The detail view controller is displayed but with no information in it! I know I must be missing something dumb but I cannot figure what!

mcpj
  • 95
  • 10
  • 1
    See http://stackoverflow.com/questions/14805954/mkannotationview-push-to-view-controller-when-detaildesclosure-button-is-clicked. When calling performSegueWithIdentifier, pass view as the sender (not self). The SIGABRT is probably because you are treating `_mapView.annotations` (which is an NSArray) as if it was a single annotation. –  Oct 06 '14 at 01:37
  • Thankyou @Anna, I updated my prepare for segue with this: -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"ABC"]) { MKAnnotationView *annotationView = sender; [segue.destinationViewController setAnnotation:annotationView.annotation]; DetailViewController *dvc = segue.destinationViewController; dvc.name = annotation.name; } } however the "annotation.name" states an error: use of undeclared identifier, I know this must be simple but where should I declare the identifier? Thanks! – mcpj Oct 08 '14 at 15:42
  • It sounds like you've mixed up or combined the storyboard and xib versions from the linked answer. Use only the storyboard version of the answer. You shouldn't be creating an instance of DetailViewController in prepareForSegue. –  Oct 08 '14 at 16:53
  • I tried to mix both methods because the storyboard version does not return any data (even though the detail view controller is correctly displayer, there is no data on in...) Now I don't want to loose your time/annoy you so maybe you could help me by giving me relevant literature/tutorials to follow? Anyway thanks again for the previous answers! – mcpj Oct 09 '14 at 11:33
  • I don't have any specific links but I suggest you start with the Apple documentation and their guides, sample apps and videos. You can also try editing your question with your latest changes and issues. Also, I don't think your issue is specifically with MapKit but is a general storyboard/segue/data-passing question. –  Oct 09 '14 at 11:59
  • I'm quite sure I need to add some code on the detail view controller, but cannot figure out what? – mcpj Oct 09 '14 at 14:54

0 Answers0