【问题标题】:Passing data from annotations to detail view iOS using storyboard使用故事板将数据从注释传递到详细视图 iOS
【发布时间】:2014-01-26 00:25:20
【问题描述】:

我正在尝试将我当前通过 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;

    }
}

【问题讨论】:

  • 我很容易在不使用故事板和笔尖的情况下完成此任务。但我正在尝试学习如何使用纯故事板。

标签: ios iphone objective-c mapkit uistoryboardsegue


【解决方案1】:

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;

    }
}

【讨论】:

  • 为什么需要额外的属性?在 prepareForSegue 中,sender 是注释视图,因此您可以使用 sender.annotation 获取注释。见stackoverflow.com/questions/14805954/…。 (顺便说一句,不管segue如何,地图视图已经有一个selectedAnnotations属性,可以告诉你哪个是选定的注释,所以不需要额外的属性。)
猜你喜欢
  • 2023-03-22
  • 1970-01-01
  • 2012-02-20
  • 2014-01-07
  • 2014-05-23
  • 1970-01-01
  • 1970-01-01
  • 2012-01-15
  • 2013-07-29
相关资源
最近更新 更多