使用故事板将数据从注释传递到详细视图iOS
我正在尝试通过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; } }
在mapView
Delegate方法中
- (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; } }