user3117785
user3117785

Reputation: 247

Passing data from annotations to detail view iOS using storyboard

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;

    }
}

Upvotes: 0

Views: 1813

Answers (1)

Bilal Saifudeen
Bilal Saifudeen

Reputation: 1677

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;

    }
}

Upvotes: 5

Related Questions