如何将带有地图视图的视图控制器中的id传递给另一个视图控制器?

时间:2014-06-10 06:13:08

标签: ios objective-c mapkit

我正在使用parse来检索数据,我如何将具有地图视图的viwecontroller中的对象ID传递给另一个视图控制器,

 -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{

    [self performSegueWithIdentifier:@"MapToDeal" sender:view.annotation];
    NSLog(@"%@",view.annotation.title);
}

1 个答案:

答案 0 :(得分:0)

在.m文件中编写此方法

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString: @"MapToDeal"])
  {
    DetailViewController *detailViewController = [segue destinationViewController];

    detailViewController.annotview = sender; //here annoteview is  object in DetailViewcontroller
  }
}

或 你也可以这样做

In mapView Delegate method

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

In prepareForSegue:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"MapToDeal"])
    {
        MapPoint *annotation = (MapPoint *)view.annotation;

        DetailViewController *dvc = segue.destinationViewController;
        dvc.name = annotation.name;
        dvc.anyproperty = annotation.anyproperty;

    }
}