本文介绍了使用故事板将数据从注释传递到详细视图iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Google Places API将我当前加载到注释中的数据传递到我通过带有segue的故事板创建的详细视图控制器。

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;

    }
}


推荐答案

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 15:55