我正在尝试将当前通过 Google Places API 加载到注释中的数据传递到我通过带有 segue 的故事板创建的详细视图控制器。
单击每个注释上的详细信息披露后,我可以正确加载详细视图控制器,但我现在正在尝试传递数据。
- (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;
}
}
In mapView
委托方式
- (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;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)