Passing data from annotations to detail view iOS using storyboard

一世执手 提交于 2019-12-01 13:04:00

问题


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;

    }
}

回答1:


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;

    }
}


来源:https://stackoverflow.com/questions/20986571/passing-data-from-annotations-to-detail-view-ios-using-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!