我正在尝试将当前已通过Google Places API加载到批注中的数据传递到我通过情节提要通过情节提要创建的详细视图控制器中。

单击每个注释上的详细信息披露后,我可以正确加载详细信息视图控制器,但现在尝试获取数据。

- (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;

    }
}

最佳答案

mapView委托方法中

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


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;

    }
}

关于ios - 使用 Storyboard 将数据从注释传递到详细 View iOS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20986571/

10-14 20:44