0

I'm trying to pass the data that I have currently loaded into annotations via Google Places API into a detail view controller that I have created via storyboard with a segue.

I have it properly loading the detail view controller upon clicking the detail disclosure on each annotation, but I'm trying to get the data passed now.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
// Assuming I call the MapPoint class here and set it to the current annotation 
// then I'm able to call each property from the MapPoint class but wouldn't 
 // I have to set this in the prepareForSegue  but that would be out of scope?

    MapPoint *annView = view.annotation;

   //   annView.name
    // annView.address

    [self performSegueWithIdentifier:@"showBarDetails" sender:view];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"showBarDetails"])
    {
        BarDetailViewController *bdvc = [self.storyboard instantiateViewControllerWithIdentifier:@"showBarDetails"];
        //This parts confusing me, not sure how I obtain the data 
        // from the above mapView delegation method?
       // annView.name = bdvc.name;
        bdvc = segue.destinationViewController;

    }
}
user3117785
  • 247
  • 5
  • 16
  • I'm easily able to accomplish this without using a storyboard and a nib.. but I'm trying to learn how to use pure storyboard. – user3117785 Jan 08 '14 at 04:03

1 Answers1

5

In mapView Delegate method

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    [self performSegueWithIdentifier:@"showBarDetails" sender:view];
}

In prepareForSegue:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"showBarDetails"])
    {
        MapPoint *annotation = (MapPoint *)view.annotation;

        BarDetailViewController *bdvc = segue.destinationViewController;
        bdvc.name = annotation.name;
        bdvc.otherProperty = annotation.otherProperty;

    }
}
Bilal Saifudeen
  • 1,677
  • 14
  • 14
  • Why do you need the extra property? In prepareForSegue, `sender` is the annotation view so you can get the annotation using sender.annotation. See http://stackoverflow.com/questions/14805954/mkannotationview-push-to-view-controller-when-detaildesclosure-button-is-clicked. (By the way, regardless of the segue, the map view already has a selectedAnnotations property that can tell you which is the selected annotation so no extra property is needed.) –  Jan 08 '14 at 14:56